Skip to content

Commit 8af4e39

Browse files
authored
Merge pull request #64 from tokenbound/bj/fix-chain-with-id-not-found-issue
Fix "Chain with id N not found" issue
2 parents 2c362fc + 7093bba commit 8af4e39

File tree

13 files changed

+495
-182
lines changed

13 files changed

+495
-182
lines changed

.changeset/happy-hounds-love.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tokenbound/sdk': patch
3+
---
4+
5+
Fix "Chain with id N not found" issue

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ VITE_PRIVATE_ALCHEMY_API_KEY=REPLACE_WITH_YOUR_ALCHEMY_API_KEY
5757

5858
# PUBLIC ENV VARS, add to `.env`:
5959
VITE_ANVIL_MAINNET_FORK_ENDPOINT=https://eth-mainnet.alchemyapi.io/v2/$VITE_PRIVATE_ALCHEMY_API_KEY
60-
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=17680029
60+
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=19364398
6161
```
6262

63-
2. Spin up an Anvil instance and start Vitest from the SDK root:
63+
2. Build the SDK from `/packages/sdk`
64+
65+
```ts copy
66+
pnpm clean && pnpm i && pnpm build
67+
```
68+
69+
3. Spin up an Anvil instance and start Vitest from the SDK root:
6470

6571
```bash copy
6672
pnpm test

examples/vite-wagmi-ethers-rainbowkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.19.11",
20+
"viem": "^1.21.4",
2121
"wagmi": "^1.4.7"
2222
},
2323
"devDependencies": {

examples/vite-wagmi-ethers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.19.11",
20+
"viem": "^1.21.4",
2121
"wagmi": "^1.4.7"
2222
},
2323
"devDependencies": {

examples/vite-wagmi-ethers6/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.19.11",
20+
"viem": "^1.21.4",
2121
"wagmi": "^1.4.7"
2222
},
2323
"devDependencies": {

examples/vite-wagmi-viem/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"react": "^18.2.0",
1818
"react-dom": "^18.2.0",
1919
"util": "^0.12.5",
20-
"viem": "^1.19.11",
20+
"viem": "^1.21.4",
2121
"wagmi": "^1.4.7"
2222
},
2323
"devDependencies": {

packages/sdk/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# PUBLIC ENV VARS, add to `.env`:
44
VITE_ANVIL_MAINNET_FORK_ENDPOINT=https://eth-mainnet.alchemyapi.io/v2/$PRIVATE_ALCHEMY_API_KEY
5-
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=18430645
5+
VITE_ANVIL_MAINNET_FORK_BLOCK_NUMBER=19364398
66

77
# PRIVATE KEYS, add to .env.local, do not commit:
88
VITE_PRIVATE_ALCHEMY_API_KEY=

packages/sdk/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tokenbound/sdk",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"type": "module",
55
"files": [
66
"dist"
@@ -25,7 +25,7 @@
2525
"wagmi": "wagmi generate"
2626
},
2727
"dependencies": {
28-
"viem": "^1.19.11"
28+
"viem": "^1.21.4"
2929
},
3030
"devDependencies": {
3131
"@tanstack/react-query": "4.29.1",
@@ -40,12 +40,12 @@
4040
"@wagmi/cli": "^1.5.2",
4141
"connectkit": "^1.5.3",
4242
"ethers": "^5.7.2",
43-
"ethers6": "npm:ethers@^6.7.1",
44-
"jsdom": "^22.1.0",
43+
"ethers6": "npm:ethers@^6.11.1",
44+
"jsdom": "^24.0.0",
4545
"react": "^18.2.0",
4646
"react-dom": "^18.2.0",
47-
"typescript": "^5.2.2",
48-
"viem": "^1.19.11",
47+
"typescript": "^5.4.2",
48+
"viem": "^1.21.4",
4949
"wagmi": "^1.4.7",
5050
"@viem/anvil": "^0.0.6",
5151
"vite": "^4.4.9",

packages/sdk/src/TokenboundClient.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
WalletClient,
33
PublicClient,
4+
Chain,
45
createPublicClient,
56
http,
67
GetBytecodeReturnType,
@@ -75,6 +76,7 @@ declare global {
7576

7677
class TokenboundClient {
7778
private chainId: number
79+
private chain: Chain
7880
public isInitialized: boolean = false
7981
public publicClient: PublicClient
8082
private supportsV3: boolean = true // Default to V3 implementation
@@ -111,6 +113,7 @@ class TokenboundClient {
111113
}
112114

113115
this.chainId = chainId ?? chain!.id
116+
this.chain = chain ?? chainIdToChain(this.chainId)
114117

115118
if (signer) {
116119
this.signer = signer
@@ -124,7 +127,7 @@ class TokenboundClient {
124127
this.publicClient =
125128
publicClient ??
126129
createPublicClient({
127-
chain: chain ?? chainIdToChain(this.chainId),
130+
chain: this.chain,
128131
transport:
129132
walletClient && !publicClientRPCUrl
130133
? custom(walletClient.transport)
@@ -315,7 +318,7 @@ class TokenboundClient {
315318
txHash = this.supportsV3
316319
? await this.walletClient.sendTransaction({
317320
...preparedCreateAccount,
318-
chain: chainIdToChain(this.chainId),
321+
chain: this.chain,
319322
account: this.walletClient?.account?.address!,
320323
}) // @BJ TODO: extract into viemV3?
321324
: await createAccount(
@@ -392,7 +395,7 @@ class TokenboundClient {
392395
return await this.walletClient.sendTransaction({
393396
// chain and account need to be added explicitly
394397
// because they're optional when instantiating a WalletClient
395-
chain: chainIdToChain(this.chainId),
398+
chain: this.chain,
396399
account: this.walletClient.account!,
397400
...preparedExecuteCall,
398401
})
@@ -462,7 +465,7 @@ class TokenboundClient {
462465
return await this.walletClient.sendTransaction({
463466
// chain and account need to be added explicitly
464467
// because they're optional when instantiating a WalletClient
465-
chain: chainIdToChain(this.chainId),
468+
chain: this.chain,
466469
account: this.walletClient.account!,
467470
...preparedExecution,
468471
})
@@ -519,7 +522,7 @@ class TokenboundClient {
519522
return await this.publicClient
520523
.getBytecode({ address: accountAddress })
521524
.then((bytecode: GetBytecodeReturnType) => {
522-
return bytecode ? bytecode.length > 2 : false
525+
return !!bytecode ? bytecode.length > 2 : false
523526
})
524527
} catch (error) {
525528
throw error

packages/sdk/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
MultiCallTx,
3232
Call3,
3333
CALL_OPERATIONS,
34+
SegmentedERC6551Bytecode
3435
} from './types'
3536

3637
import {
@@ -77,4 +78,5 @@ export type {
7778
TBImplementationVersion,
7879
MultiCallTx,
7980
Call3,
81+
SegmentedERC6551Bytecode
8082
}

0 commit comments

Comments
 (0)