Skip to content

Commit 7523569

Browse files
committed
fix bug 'Cannot convert undefined to a BigInt' with our viem implementation, turns out you cannot supply a chain id as an int to createPublicClient and createWalletClient, but you instead need to require the Chain type from viem itself
1 parent 487b87e commit 7523569

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

run-claim.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
const axios = require('axios');
2-
const { http, createPublicClient } = require('viem');
2+
3+
const { worldchain } = require('viem/chains');
4+
const { http, createPublicClient, createWalletClient } = require('viem');
35
const { privateKeyToAccount } = require('viem/accounts');
46

57
const CHAIN_ID = 480;
6-
const USER_PRIZE_VAULT_ADDRESS = '0x4c7e1f64a4b121d2f10d6fbca0db143787bf64bb';
8+
const USER_PRIZE_VAULT_ADDRESS = '0x4c7E1f64A4b121D2F10D6FbcA0DB143787BF64bB';
79
const WORLD_TOKEN_ADDRESS = '0x2cFc85d8E48F8EAB294be644d9E25C3030863003';
810
const MERKL_DISTRIBUTOR_CONTRACT_ADDRESS = '0x3Ef3D8bA38EBe18DB133cEc108f4D14CE00Dd9Ae';
911

@@ -55,17 +57,21 @@ async function sendTransaction(claimData) {
5557
// Merkl Distributor Proxy Contract
5658
const users = [USER_PRIZE_VAULT_ADDRESS];
5759
const tokens = [WORLD_TOKEN_ADDRESS];
58-
const amounts = [claimData.unclaimed];
60+
const amounts = [claimData.accumulated];
5961
const proofs = [claimData.proof];
6062

6163
try {
6264
const account = privateKeyToAccount(`0x${privateKey}`);
6365
const publicClient = createPublicClient({
64-
chain: 480, // You can specify a chain if needed, e.g., mainnet, goerli, etc.
66+
chain: worldchain,
67+
transport: http(rpcUrl),
68+
});
69+
const walletClient = createWalletClient({
70+
chain: worldchain,
6571
transport: http(rpcUrl),
72+
account,
6673
});
6774

68-
// Simulate the transaction
6975
const { request } = await publicClient.simulateContract({
7076
address: MERKL_DISTRIBUTOR_CONTRACT_ADDRESS,
7177
abi: CLAIM_ABI,
@@ -74,11 +80,9 @@ async function sendTransaction(claimData) {
7480
account,
7581
});
7682

77-
// Execute the transaction
78-
const hash = await publicClient.writeContract(request);
83+
const hash = await walletClient.writeContract(request);
7984
console.log('Transaction hash:', hash);
8085

81-
// Optionally, you can wait for the transaction receipt
8286
const transactionReceipt = await publicClient.waitForTransactionReceipt({ hash });
8387
console.log('Transaction receipt:', transactionReceipt);
8488
} catch (err) {

0 commit comments

Comments
 (0)