SoFunction
Updated on 2025-03-03

Add (txhash) method steps

eth_getRawTransactionByHash

/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 web3 under the project node_modules and find the file below

Eth

Add methods to the class

 getRawTransaction(hash: string, cb?: Callback<TransactionRaw>): Promise<TransactionRaw>

Add TransactionRaw definition

export declare interface TransactionRaw {
 raw: string
}

2. Find the project node_modules in web3-eth

methods={}

Add method

new Method({
   name: 'getRawTransaction',
   call: 'eth_getRawTransactionByHash',
   params: 1,
   inputFormatter: [null],
   outputFormatter: 
  }),

3. Find the web3-core-helpers under the project node_modules

Add outputTransactionRawFormatter and also add the corresponding

/**
 * Formats the output of a transaction raw value
 *
 * @method outputTransactionRawFormatter
 * @param {Object} tx
 * @returns {Object}
*/
var outputTransactionRawFormatter = function (tx){
 return tx;
};
 = {
 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
};

Note: The above code is version 1.0.

Summarize

The above is the steps for adding (txhash) introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!