-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
93 lines (84 loc) · 2.37 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { parseGwei, stringToHex, toBlobs, parseEther, setupKzg, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from "viem/accounts";
import { sepolia } from 'viem/chains'
import * as cKzg from 'c-kzg'
import { resolve } from 'path'
import dotenv from "dotenv";
dotenv.config();
const PRIVATE_KEY: string = process.env.PRIVATEKEY
const mainnetTrustedSetupPath = resolve(
'./mainnet.json',
)
const kzg = setupKzg(cKzg, mainnetTrustedSetupPath);
const blobs = toBlobs({ data: stringToHex('hello world') });
const account = privateKeyToAccount(`0x${PRIVATE_KEY}`);
const client = createWalletClient({
account,
chain: sepolia,
transport: http()
});
async function type0transaction() {
const hash = await client.sendTransaction({
account,
kzg,
to: '0x0000000000000000000000000000000000000000',
value: parseEther('1'),
chain: sepolia,
gasPrice: parseGwei('11'),
gas: 21000n,
})
console.log("TxHash:", hash)
}
export type AccessList = {
address: `0x${string}`;
storageKeys: `0x${string}`[];
}[];
const accessList: AccessList = [
{
address: '0x0000000000000000000000000000000000000000',
storageKeys: [
'0x0000000000000000000000000000000000000000000000000000000000000000'
]
}
];
async function type1transaction() {
const hash = await client.sendTransaction({
account,
kzg,
to: '0x0000000000000000000000000000000000000000',
value: 1n,
chain: sepolia,
gas: 30000n,
accessList: accessList,
})
console.log("TxHash:", hash)
}
async function type2transaction() {
const hash = await client.sendTransaction({
account,
kzg,
to: '0x0000000000000000000000000000000000000000',
value: 1n,
chain: sepolia,
maxFeePerGas: parseGwei('30'),
maxPriorityFeePerGas: parseGwei('3'),
gas: 21000n,
})
console.log("TxHash:", hash)
}
async function type3transaction() {
const hash = await client.sendTransaction({
account,
blobs: blobs,
kzg,
maxFeePerBlobGas: parseGwei('300'),
to: '0x0000000000000000000000000000000000000000',
chain: sepolia,
gas: 21000n,
})
console.log(`Transaction : https://sepolia.etherscan.io/tx/${hash}`)
}
// type0transaction();
// type1transaction();
// type2transaction();
type3transaction();