|
2 | 2 |
|
3 | 3 | import { env } from '../tools/lib/index.ts' |
4 | 4 | import { abis } from '../codegen/abis.ts' |
5 | | -import { Storage } from '../codegen/addresses.ts' |
| 5 | +import { Test } from '../codegen/addresses.ts' |
| 6 | +import { encodeFunctionData } from 'viem' |
6 | 7 |
|
7 | | -{ |
8 | | - const { request } = await env.wallet.simulateContract({ |
9 | | - address: Storage, |
10 | | - abi: abis.Storage, |
11 | | - functionName: 'store', |
12 | | - args: [42n], |
13 | | - }) |
| 8 | +switch (Deno.env.get('ACTION')) { |
| 9 | + case 'execute': { |
| 10 | + const { request } = await env.wallet.simulateContract({ |
| 11 | + address: Test, |
| 12 | + abi: abis.Test, |
| 13 | + functionName: 'tryCatchNewContract', |
| 14 | + args: ['0x0000000000000000000000000000000000000000'], |
| 15 | + }) |
14 | 16 |
|
15 | | - const result = await env.wallet.writeContract(request) |
16 | | - console.log('store tx', result) |
17 | | -} |
| 17 | + const hash = await env.wallet.writeContract(request) |
| 18 | + const receipt = await env.wallet.waitForTransactionReceipt({ |
| 19 | + hash, |
| 20 | + }) |
| 21 | + |
| 22 | + const res = await env.debugClient.traceTransaction( |
| 23 | + receipt.transactionHash, |
| 24 | + 'callTracer', |
| 25 | + {}, |
| 26 | + ) |
| 27 | + console.log(JSON.stringify(res)) |
| 28 | + break |
| 29 | + } |
| 30 | + |
| 31 | + case 'estimate': { |
| 32 | + const res = await env.wallet.estimateContractGas({ |
| 33 | + address: Test, |
| 34 | + abi: abis.Test, |
| 35 | + functionName: 'tryCatchNewContract', |
| 36 | + args: ['0x0000000000000000000000000000000000000000'], |
| 37 | + }) |
| 38 | + |
| 39 | + console.log(res) |
| 40 | + break |
| 41 | + } |
18 | 42 |
|
19 | | -{ |
20 | | - const result = await env.wallet.readContract( |
21 | | - { |
22 | | - address: Storage, |
23 | | - abi: abis.Storage, |
24 | | - functionName: 'retrieve', |
25 | | - }, |
26 | | - ) |
27 | | - console.log('retrieve:', result) |
| 43 | + default: { |
| 44 | + const res = await env.debugClient.traceCall( |
| 45 | + { |
| 46 | + account: env.wallet.account, |
| 47 | + gas: 28663198355n, // * 140n / 100n, |
| 48 | + to: Test, |
| 49 | + data: encodeFunctionData({ |
| 50 | + abi: abis.Test, |
| 51 | + functionName: 'tryCatchNewContract', |
| 52 | + args: ['0x0000000000000000000000000000000000000000'], |
| 53 | + }), |
| 54 | + }, |
| 55 | + 'callTracer', |
| 56 | + {}, |
| 57 | + ) |
| 58 | + console.log(JSON.stringify(res)) |
| 59 | + } |
28 | 60 | } |
0 commit comments