web3.js增加eth.getRawTransactionByHash(txhash)方法步骤
eth_getRawTransactionByHash
https://ethereum.stackexchange.com/questions/7473/get-raw-transaction-from-hash
Thereisan"undocumented"methodeth_getRawTransactionByHashfromJSON-RPC
curl-H"Content-Type:application/json"-XPOST--data\ '{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":[""],"id":1}'http://localhost:8545 -transactionid
1.项目node_modules下找到web3 下types.d.ts文件
Eth
类中增加方法
getRawTransaction(hash:string,cb?:Callback):Promise
增加TransactionRaw定义
exportdeclareinterfaceTransactionRaw{ raw:string }
2.项目node_modules下找到web3-eth中 index.js
methods={}
增加方法
newMethod({ name:'getRawTransaction', call:'eth_getRawTransactionByHash', params:1, inputFormatter:[null], outputFormatter:formatter.outputTransactionRawFormatter }),
3.项目node_modules下找到web3-core-helpers中 formatters.js
增加outputTransactionRawFormatter并module.exports中也增加对应
/** *Formatstheoutputofatransactionrawvalue * *@methodoutputTransactionRawFormatter *@param{Object}tx *@returns{Object} */ varoutputTransactionRawFormatter=function(tx){ returntx; }; 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)方法步骤,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!