Created
December 15, 2022 05:32
-
-
Save korrio/81edf05878e5229aacd20e0bf0671ddd to your computer and use it in GitHub Desktop.
ChatGPT log on Ethereum Transaction Data Structure in NodeJS
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 EthereumTx = require('ethereumjs-tx'); | |
// raw transaction data | |
const rawTx = '0xf86d8202b28477359400825208944592d8f8d7b001e72cb26a73e4fa1806a51ac79d880de0b6b3a76400008025a028ef61340bd939bc2e7b2a7b190d114d4c7e8a3d80e95599b63f6821023a9c7f3cf3e1df715f0d5c5b5e8d8b82e3538abf2e5b08cc8c86905b776f5dbb82c7'; | |
// create a new transaction object | |
const tx = new EthereumTx(rawTx); | |
// access the data fields of the transaction | |
console.log(`nonce: ${tx.nonce}`); | |
console.log(`gasPrice: ${tx.gasPrice}`); | |
console.log(`gasLimit: ${tx.gasLimit}`); | |
console.log(`to: ${tx.to}`); | |
console.log(`value: ${tx.value}`); | |
console.log(`data: ${tx.data}`); | |
console.log(`v: ${tx.v}`); | |
console.log(`r: ${tx.r}`); | |
console.log(`s: ${tx.s}`); |
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
interface Transaction { | |
nonce: string; | |
gasPrice: string; | |
gasLimit: string; | |
to: string; | |
value: string; | |
data: string; | |
v: string; | |
r: string; | |
s: string; | |
} |
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
let transaction: Transaction = { | |
nonce: '0x00', | |
gasPrice: '0x09184e72a000', | |
gasLimit: '0x2710', | |
to: '0x0000000000000000000000000000000000000000', | |
value: '0x00', | |
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057', | |
v: '0x1c', | |
r: '0x5e1d3a76fbf824220eafc8c79ad578ad2b67d01b0c2425eb1f1347e8f50882ab', | |
s: '0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13' | |
} | |
class Transaction { | |
nonce: string; | |
gasPrice: string; | |
gasLimit: string; | |
to: string; | |
value: string; | |
data: string; | |
v: string; | |
r: string; | |
s: string; | |
constructor(nonce: string, gasPrice: string, gasLimit: string, to: string, value: string, data: string, v: string, r: string, s: string) { | |
this.nonce = nonce; | |
this.gasPrice = gasPrice; | |
this.gasLimit = gasLimit; | |
this.to = to; | |
this.value = value; | |
this.data = data; | |
this.v = v; | |
this.r = r; | |
this.s = s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment