1
1
import { Common , Hardfork , Mainnet } from '@ethereumjs/common'
2
- import { createEOACode7702Tx } from '@ethereumjs/tx'
3
- import { type PrefixedHexString , createAddressFromPrivateKey , randomBytes } from '@ethereumjs/util'
2
+ import { Capability , createEOACode7702Tx } from '@ethereumjs/tx'
3
+ import {
4
+ EOACode7702AuthorizationListItem ,
5
+ type PrefixedHexString ,
6
+ createAddressFromPrivateKey ,
7
+ randomBytes ,
8
+ } from '@ethereumjs/util'
4
9
5
- const ones32 = `0x${ '01' . repeat ( 32 ) } ` as PrefixedHexString
10
+ const ones32 : PrefixedHexString = `0x${ '01' . repeat ( 32 ) } `
11
+ const authorizationListItem : EOACode7702AuthorizationListItem = {
12
+ chainId : '0x2' ,
13
+ address : `0x${ '20' . repeat ( 20 ) } ` ,
14
+ nonce : '0x1' ,
15
+ yParity : '0x1' ,
16
+ r : ones32 ,
17
+ s : ones32 ,
18
+ }
6
19
7
- const common = new Common ( { chain : Mainnet , hardfork : Hardfork . Cancun , eips : [ 7702 ] } )
20
+ const common = new Common ( { chain : Mainnet , hardfork : Hardfork . Prague } )
8
21
const tx = createEOACode7702Tx (
9
22
{
10
- authorizationList : [
11
- {
12
- chainId : '0x2' ,
13
- address : `0x${ '20' . repeat ( 20 ) } ` ,
14
- nonce : '0x1' ,
15
- yParity : '0x1' ,
16
- r : ones32 ,
17
- s : ones32 ,
18
- } ,
19
- ] ,
23
+ authorizationList : [ authorizationListItem ] ,
20
24
to : createAddressFromPrivateKey ( randomBytes ( 32 ) ) ,
21
25
} ,
22
26
{ common } ,
@@ -25,3 +29,4 @@ const tx = createEOACode7702Tx(
25
29
console . log (
26
30
`EIP-7702 EOA code tx created with ${ tx . authorizationList . length } authorization list item(s).` ,
27
31
)
32
+ console . log ( 'Tx supports EIP-7702? ' , tx . supports ( Capability . EIP7702EOACode ) )
0 commit comments