这篇文章将为大家详细讲解有关web3.js如何增加eth.getRawTransactionByHash(txhash)方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
eth_getRawTransactionByHash
https://ethereum.stackexchange.com/questions/7473/get-raw-transaction-from-hash
There is an "undocumented" method eth_getRawTransactionByHash from JSON-RPC
curl -H "Content-Type: application/json" -X POST --data \ '{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}' http://localhost:8545 <TX_HASH> - transaction id
1.项目node_modules 下找到web3 下types.d.ts文件
Eth
类中增加方法
getRawTransaction(hash: string, cb?: Callback<TransactionRaw>): Promise<TransactionRaw>
增加TransactionRaw定义
export declare interface TransactionRaw { raw: string }
2.项目node_modules 下找到 web3-eth中 index.js
methods={}
增加方法
new Method({ name: 'getRawTransaction', call: 'eth_getRawTransactionByHash', params: 1, inputFormatter: [null], outputFormatter: formatter.outputTransactionRawFormatter }),
3.项目node_modules 下找到 web3-core-helpers中 formatters.js
增加 outputTransactionRawFormatter并module.exports中也增加对应
/** * Formats the output of a transaction raw value * * @method outputTransactionRawFormatter * @param {Object} tx * @returns {Object} */ var outputTransactionRawFormatter = function (tx){ return tx; }; module.exports = { inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, inputBlockNumberFormatter: inputBlockNumberFormatter, inputCallFormatter: inputCallFormatter, inputTransactionFormatter: inputTransactionFormatter, inputAddressFormatter: inputAddressFormatter, inputPostFormatter: inputPostFormatter, inputLogFormatter: inputLogFormatter, inputSignFormatter: inputSignFormatter, outputBigNumberFormatter: outputBigNumberFormatter, outputTransactionFormatter: outputTransactionFormatter, outputTransactionRawFormatter: outputTransactionRawFormatter, outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, outputBlockFormatter: outputBlockFormatter, outputLogFormatter: outputLogFormatter, outputPostFormatter: outputPostFormatter, outputSyncingFormatter: outputSyncingFormatter };
备注:以上代码是1.0.版本的
关于“web3.js如何增加eth.getRawTransactionByHash(txhash)方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。