File tree 6 files changed +17
-12
lines changed 6 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 1
1
import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
2
+ import type { AccessList2930TxData } from '@ethereumjs/tx'
2
3
import { createAccessList2930Tx } from '@ethereumjs/tx'
3
4
import { bytesToHex } from '@ethereumjs/util'
4
5
5
6
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . Berlin } )
6
7
7
- const txData = {
8
+ const txData : AccessList2930TxData = {
8
9
data : '0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
9
10
gasLimit : '0x02625a00' ,
10
11
gasPrice : '0x01' ,
Original file line number Diff line number Diff line change 1
1
import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
2
+ import type { BlobEIP4844TxData } from '@ethereumjs/tx'
2
3
import { createBlob4844Tx } from '@ethereumjs/tx'
3
4
import { bytesToHex } from '@ethereumjs/util'
4
5
import { trustedSetup } from '@paulmillr/trusted-setups/fast.js'
@@ -13,12 +14,12 @@ const main = async () => {
13
14
customCrypto : { kzg } ,
14
15
} )
15
16
16
- const txData = {
17
+ const txData : BlobEIP4844TxData = {
17
18
data : '0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
18
19
gasLimit : '0x02625a00' ,
19
20
maxPriorityFeePerGas : '0x01' ,
20
21
maxFeePerGas : '0xff' ,
21
- maxFeePerDataGas : '0xfff' ,
22
+ maxFeePerBlobGas : '0xfff' ,
22
23
nonce : '0x00' ,
23
24
to : '0xcccccccccccccccccccccccccccccccccccccccc' ,
24
25
value : '0x0186a0' ,
Original file line number Diff line number Diff line change 1
1
import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
2
+ import type { LegacyTxData } from '@ethereumjs/tx'
2
3
import { createLegacyTx } from '@ethereumjs/tx'
3
4
import { bytesToHex , hexToBytes } from '@ethereumjs/util'
4
5
5
- const txParams = {
6
+ const txData : LegacyTxData = {
6
7
nonce : '0x0' ,
7
8
gasPrice : '0x09184e72a000' ,
8
9
gasLimit : '0x2710' ,
@@ -12,7 +13,7 @@ const txParams = {
12
13
}
13
14
14
15
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . Istanbul } )
15
- const tx = createLegacyTx ( txParams , { common } )
16
+ const tx = createLegacyTx ( txData , { common } )
16
17
17
18
const privateKey = hexToBytes ( '0xe331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109' )
18
19
Original file line number Diff line number Diff line change 1
1
import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
2
+ import type { FeeMarketEIP1559TxData } from '@ethereumjs/tx'
2
3
import { createFeeMarket1559Tx } from '@ethereumjs/tx'
3
4
import { bytesToHex } from '@ethereumjs/util'
4
5
5
6
const common = new Common ( { chain : Mainnet , hardfork : Hardfork . London } )
6
7
7
- const txData = {
8
+ const txData : FeeMarketEIP1559TxData = {
8
9
data : '0x1a8451e600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ,
9
10
gasLimit : '0x02625a00' ,
10
11
maxPriorityFeePerGas : '0x01' ,
Original file line number Diff line number Diff line change 3
3
// Install the dependencies and run `npx tsx examples/transactions.ts`
4
4
5
5
import { createLegacyTx , createLegacyTxFromBytesArray } from '@ethereumjs/tx'
6
- import { bytesToHex , hexToBytes , toBytes } from '@ethereumjs/util'
6
+ import type { PrefixedHexString } from '@ethereumjs/util'
7
+ import { bytesToHex , hexToBytes } from '@ethereumjs/util'
7
8
8
9
// We create an unsigned transaction.
9
10
// Notice we don't set the `to` field because we are creating a new contract.
@@ -38,7 +39,7 @@ console.log('--------------------')
38
39
// If you got it directly from the network it will be rlp encoded.
39
40
// You can decode it with the rlp module.
40
41
// After that you should have something like:
41
- const rawTx = [
42
+ const rawTx : PrefixedHexString [ ] = [
42
43
'0x' ,
43
44
'0x09184e72a000' ,
44
45
'0x2710' ,
@@ -50,7 +51,7 @@ const rawTx = [
50
51
'0x5bd428537f05f9830e93792f90ea6a3e2d1ee84952dd96edbae9f658f831ab13' ,
51
52
]
52
53
53
- const tx2 = createLegacyTxFromBytesArray ( rawTx . map ( toBytes ) ) // This is also a mainnet transaction
54
+ const tx2 = createLegacyTxFromBytesArray ( rawTx . map ( hexToBytes ) ) // This is also a mainnet transaction
54
55
55
56
// So assuming that you were able to parse the transaction, we will now get the sender's address.
56
57
Original file line number Diff line number Diff line change @@ -24,20 +24,20 @@ export const bytesToUnprefixedHex = _bytesToUnprefixedHex
24
24
* @returns {Uint8Array } The converted bytes
25
25
* @throws If the input is not a valid 0x-prefixed hex string
26
26
*/
27
- export const hexToBytes = ( hex : string ) => {
27
+ export const hexToBytes = ( hex : string ) : Uint8Array => {
28
28
if ( ! hex . startsWith ( '0x' ) ) throw EthereumJSErrorWithoutCode ( 'input string must be 0x prefixed' )
29
29
return nobleH2B ( padToEven ( stripHexPrefix ( hex ) ) )
30
30
}
31
31
32
- export const unprefixedHexToBytes = ( hex : string ) => {
32
+ export const unprefixedHexToBytes = ( hex : string ) : Uint8Array => {
33
33
if ( hex . startsWith ( '0x' ) ) throw EthereumJSErrorWithoutCode ( 'input string cannot be 0x prefixed' )
34
34
return nobleH2B ( padToEven ( hex ) )
35
35
}
36
36
37
37
export const bytesToHex = ( bytes : Uint8Array ) : PrefixedHexString => {
38
38
if ( bytes === undefined || bytes . length === 0 ) return '0x'
39
39
const unprefixedHex = bytesToUnprefixedHex ( bytes )
40
- return ( '0x' + unprefixedHex ) as PrefixedHexString
40
+ return `0x ${ unprefixedHex } `
41
41
}
42
42
43
43
// BigInt cache for the numbers 0 - 256*256-1 (two-byte bytes)
You can’t perform that action at this time.
0 commit comments