欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

web3.js增加eth.getRawTransactionByHash(txhash)方法步骤

程序员文章站 2023-10-29 14:10:46
eth_getrawtransactionbyhash there is an "undocumented" method eth_getrawtransacti...

eth_getrawtransactionbyhash

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)方法步骤,希望对大家有所帮助