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={}
##Add method
new Method({ name: 'getRawTransaction', call: 'eth_getRawTransactionByHash', params: 1, inputFormatter: [null], outputFormatter: formatter.outputTransactionRawFormatter }),
/** * 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’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!