Home >Web Front-end >JS Tutorial >web3.js adds eth.getRawTransactionByHash(txhash) method steps
This article mainly introduces the steps of adding eth.getRawTransactionByHash (txhash) method to web3.js. Friends in need can refer to
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. Find the types.d.ts file under web3 under the project node_modules
Eth
Add a method to the class
getRawTransaction(hash: string, cb?: Callback<TransactionRaw>): Promise<TransactionRaw>
Add TransactionRaw definition
export declare interface TransactionRaw { raw: string }
2. Find index.js
methods={}# under the project node_modules in web3-eth
##Add method
new Method({ name: 'getRawTransaction', call: 'eth_getRawTransactionByHash', params: 1, inputFormatter: [null], outputFormatter: formatter.outputTransactionRawFormatter }),3. Find formatters.js in web3-core-helpers under the project node_modules Add outputTransactionRawFormatter and add the corresponding one in 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 };The above is what I compiled for everyone. I hope it will be helpful to everyone in the future. . Related articles:
Vue’s routing dynamic redirection and navigation guard examples
JS implementation as dynamically created elements Add event operation example
Introduction to the calling sequence of functions in vue
The above is the detailed content of web3.js adds eth.getRawTransactionByHash(txhash) method steps. For more information, please follow other related articles on the PHP Chinese website!