您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。