Home > Web Front-end > JS Tutorial > web3.js adds eth.getRawTransactionByHash(txhash) method steps

web3.js adds eth.getRawTransactionByHash(txhash) method steps

亚连
Release: 2018-05-30 10:20:10
Original
2600 people have browsed it

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 \
&#39;{"jsonrpc":"2.0","method":"eth_getRawTransactionByHash","params":["<TX_HASH>"],"id":1}&#39; http://localhost:8545
<TX_HASH> - transaction id
Copy after login

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>
Copy after login

Add TransactionRaw definition

export declare interface TransactionRaw {
 raw: string
}
Copy after login

2. Find index.js

methods={}
Copy after login
# under the project node_modules in web3-eth

##Add method

new Method({
   name: &#39;getRawTransaction&#39;,
   call: &#39;eth_getRawTransactionByHash&#39;,
   params: 1,
   inputFormatter: [null],
   outputFormatter: formatter.outputTransactionRawFormatter
  }),
Copy after login

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
};
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template