首页  >  文章  >  web前端  >  web3.js增加eth.getRawTransactionByHash(txhash)方法步骤

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

亚连
亚连原创
2018-05-30 10:20:102575浏览

这篇文章主要介绍了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 \
&#39;{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}&#39; 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: &#39;getRawTransaction&#39;,
   call: &#39;eth_getRawTransactionByHash&#39;,
   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
};

上面是我整理给大家的,希望今后会对大家有帮助。

相关文章:

Vue的路由动态重定向和导航守卫实例

JS实现为动态创建的元素添加事件操作示例

对vue里函数的调用顺序介绍

以上是web3.js增加eth.getRawTransactionByHash(txhash)方法步骤的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn