Created
June 15, 2024 09:26
-
-
Save 1500256797/8a69739dadadd49713d48debc12caf77 to your computer and use it in GitHub Desktop.
parse eth raw tx using etherjs v5.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ethers = require('ethers') | |
async function main() { | |
let raw_tx = | |
'0xf86a21850389dffde682b3b094fe2c232addf66539bfd5d1bd4b2cc91d358022a286b5e620f480008026a035df2b615912b8be79a13c9b0a1540ade55434ab68778a49943442a9e6d3141aa00a6e33134ba47c1f1cda59ec3ef62a59d4da6a9d111eb4e447828574c1c94f66' | |
let tx = ethers.utils.parseTransaction(raw_tx) | |
// tx : { | |
// nonce: 33, | |
// gasPrice: BigNumber { _hex: '0x0389dffde6', _isBigNumber: true }, | |
// gasLimit: BigNumber { _hex: '0xb3b0', _isBigNumber: true }, | |
// to: '0xfe2c232adDF66539BFd5d1Bd4B2cc91D358022a2', | |
// value: BigNumber { _hex: '0xb5e620f48000', _isBigNumber: true }, | |
// data: '0x', | |
// chainId: 1, | |
// v: 38, | |
// r: '0x35df2b615912b8be79a13c9b0a1540ade55434ab68778a49943442a9e6d3141a', | |
// s: '0x0a6e33134ba47c1f1cda59ec3ef62a59d4da6a9d111eb4e447828574c1c94f66', | |
// from: '0x49aB56B91fc982Fd6Ec1EC7Bb87d74EFA6dA30ab', | |
// hash: '0xc20d7398343b00d1bc5aaf8f6d9a879217003d6cc726053cd41fb960977cd066', | |
// type: null | |
// } | |
console.log('tx : ', tx) | |
// print pretty | |
//nonce : 33 | |
// gasPrice : 15198060006 | |
// gasLimit : 46000 | |
// to : 0xfe2c232adDF66539BFd5d1Bd4B2cc91D358022a2 | |
// value : 200000000000000 | |
// data : 0x | |
// chainId : 1 | |
// v : 38 | |
// r : 0x35df2b615912b8be79a13c9b0a1540ade55434ab68778a49943442a9e6d3141a | |
// s : 0x0a6e33134ba47c1f1cda59ec3ef62a59d4da6a9d111eb4e447828574c1c94f66 | |
// from : 0x49aB56B91fc982Fd6Ec1EC7Bb87d74EFA6dA30ab | |
// hash : 0xc20d7398343b00d1bc5aaf8f6d9a879217003d6cc726053cd41fb960977cd066 | |
// type : null | |
console.log('nonce : ', tx.nonce) | |
console.log('gasPrice : ', tx.gasPrice.toString()) | |
console.log('gasLimit : ', tx.gasLimit.toString()) | |
console.log('to : ', tx.to) | |
console.log('value : ', tx.value.toString()) | |
console.log('data : ', tx.data) | |
console.log('chainId : ', tx.chainId) | |
console.log('v : ', tx.v) | |
console.log('r : ', tx.r) | |
console.log('s : ', tx.s) | |
console.log('from : ', tx.from) | |
console.log('hash : ', tx.hash) | |
console.log('type : ', tx.type) | |
} | |
main() | |
.then(() => process.exit(0)) | |
.catch((error) => { | |
console.error(error) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment