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

NO IMAGE

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)方法步驟,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回覆大家的。在此也非常感謝大家對指令碼之家網站的支援!