-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
108 lines (80 loc) · 2.5 KB
/
index.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
92
93
94
95
96
97
98
99
100
101
102
103
104
import { createPublicClient, createWalletClient, defineChain, encodeFunctionData, http, keccak256, type Block, type TransactionRequestEIP1559 } from "viem"
import { privateKeyToAccount } from "viem/accounts"
const happyTestnet = defineChain({
id: 216,
name: "Happy Testnet",
rpcUrls: {
default: {
http: ["https://happy-testnet-sepolia.rpc.caldera.xyz/http"],
},
},
nativeCurrency: {
name: "HAPPY",
symbol: "HAPPY",
decimals: 18,
},
})
const contractAddress = "0x207E51b45E0A55410F54C371616b5A26A4703DED"
const abi = [
{
"inputs": [],
"name": "increment",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
] as const
const data = encodeFunctionData({
abi,
functionName: "increment",
})
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)
console.log(account.address)
const publicClient = createPublicClient({
chain: happyTestnet,
transport: http(),
})
const walletClient = createWalletClient({
account,
chain: happyTestnet,
transport: http(),
})
let nonce = await publicClient.getTransactionCount({
address: account.address,
})
const delayTimes = []
const quantityOfTransactions = 10
for (let i = 0; i < quantityOfTransactions; i++) {
const transactionParams: TransactionRequestEIP1559 & { gas: bigint, chainId: number } = {
type: "eip1559",
from: account.address,
to: contractAddress,
data,
value: 0n,
nonce,
maxFeePerGas: 300n,
maxPriorityFeePerGas: 0n,
gas: 30000n,
chainId: happyTestnet.id,
}
const signedTransaction = await walletClient.account.signTransaction(transactionParams)
const hash = keccak256(signedTransaction)
await walletClient.sendRawTransaction({
serializedTransaction: signedTransaction,
})
console.log("Transaction with hash", hash)
const sentIn = Date.now()
console.log("Sent in", sentIn)
const receipt = await publicClient.waitForTransactionReceipt({
hash,
})
const includedBlock = await publicClient.getBlock({
blockNumber: receipt.blockNumber,
})
const includedIn = Number(includedBlock.timestamp) * 1000
console.log("Included in", includedIn)
console.log("--------------------------------")
delayTimes.push(includedIn - sentIn)
nonce++
}
console.log("Average delay", delayTimes.reduce((a, b) => a + b, 0) / delayTimes.length)