Skip to content

Commit

Permalink
Merge pull request #64 from tokenbound/bj/fix-chain-with-id-not-found…
Browse files Browse the repository at this point in the history
…-issue

Fix "Chain with id N not found" issue
  • Loading branch information
bjfresh authored Mar 8, 2024
2 parents 2c362fc + 7093bba commit 8af4e39
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 182 deletions.
5 changes: 5 additions & 0 deletions .changeset/happy-hounds-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tokenbound/sdk': patch
---

Fix "Chain with id N not found" issue
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,16 @@ VITE_PRIVATE_ALCHEMY_API_KEY=REPLACE_WITH_YOUR_ALCHEMY_API_KEY

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

2. Spin up an Anvil instance and start Vitest from the SDK root:
2. Build the SDK from `/packages/sdk`

```ts copy
pnpm clean && pnpm i && pnpm build
```

3. Spin up an Anvil instance and start Vitest from the SDK root:

```bash copy
pnpm test
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-wagmi-ethers-rainbowkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.19.11",
"viem": "^1.21.4",
"wagmi": "^1.4.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-wagmi-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.19.11",
"viem": "^1.21.4",
"wagmi": "^1.4.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-wagmi-ethers6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.19.11",
"viem": "^1.21.4",
"wagmi": "^1.4.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/vite-wagmi-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"util": "^0.12.5",
"viem": "^1.19.11",
"viem": "^1.21.4",
"wagmi": "^1.4.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

# PRIVATE KEYS, add to .env.local, do not commit:
VITE_PRIVATE_ALCHEMY_API_KEY=
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tokenbound/sdk",
"version": "0.4.5",
"version": "0.4.6",
"type": "module",
"files": [
"dist"
Expand All @@ -25,7 +25,7 @@
"wagmi": "wagmi generate"
},
"dependencies": {
"viem": "^1.19.11"
"viem": "^1.21.4"
},
"devDependencies": {
"@tanstack/react-query": "4.29.1",
Expand All @@ -40,12 +40,12 @@
"@wagmi/cli": "^1.5.2",
"connectkit": "^1.5.3",
"ethers": "^5.7.2",
"ethers6": "npm:ethers@^6.7.1",
"jsdom": "^22.1.0",
"ethers6": "npm:ethers@^6.11.1",
"jsdom": "^24.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.2.2",
"viem": "^1.19.11",
"typescript": "^5.4.2",
"viem": "^1.21.4",
"wagmi": "^1.4.7",
"@viem/anvil": "^0.0.6",
"vite": "^4.4.9",
Expand Down
13 changes: 8 additions & 5 deletions packages/sdk/src/TokenboundClient.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
WalletClient,
PublicClient,
Chain,
createPublicClient,
http,
GetBytecodeReturnType,
Expand Down Expand Up @@ -75,6 +76,7 @@ declare global {

class TokenboundClient {
private chainId: number
private chain: Chain
public isInitialized: boolean = false
public publicClient: PublicClient
private supportsV3: boolean = true // Default to V3 implementation
Expand Down Expand Up @@ -111,6 +113,7 @@ class TokenboundClient {
}

this.chainId = chainId ?? chain!.id
this.chain = chain ?? chainIdToChain(this.chainId)

if (signer) {
this.signer = signer
Expand All @@ -124,7 +127,7 @@ class TokenboundClient {
this.publicClient =
publicClient ??
createPublicClient({
chain: chain ?? chainIdToChain(this.chainId),
chain: this.chain,
transport:
walletClient && !publicClientRPCUrl
? custom(walletClient.transport)
Expand Down Expand Up @@ -315,7 +318,7 @@ class TokenboundClient {
txHash = this.supportsV3
? await this.walletClient.sendTransaction({
...preparedCreateAccount,
chain: chainIdToChain(this.chainId),
chain: this.chain,
account: this.walletClient?.account?.address!,
}) // @BJ TODO: extract into viemV3?
: await createAccount(
Expand Down Expand Up @@ -392,7 +395,7 @@ class TokenboundClient {
return await this.walletClient.sendTransaction({
// chain and account need to be added explicitly
// because they're optional when instantiating a WalletClient
chain: chainIdToChain(this.chainId),
chain: this.chain,
account: this.walletClient.account!,
...preparedExecuteCall,
})
Expand Down Expand Up @@ -462,7 +465,7 @@ class TokenboundClient {
return await this.walletClient.sendTransaction({
// chain and account need to be added explicitly
// because they're optional when instantiating a WalletClient
chain: chainIdToChain(this.chainId),
chain: this.chain,
account: this.walletClient.account!,
...preparedExecution,
})
Expand Down Expand Up @@ -519,7 +522,7 @@ class TokenboundClient {
return await this.publicClient
.getBytecode({ address: accountAddress })
.then((bytecode: GetBytecodeReturnType) => {
return bytecode ? bytecode.length > 2 : false
return !!bytecode ? bytecode.length > 2 : false
})
} catch (error) {
throw error
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
MultiCallTx,
Call3,
CALL_OPERATIONS,
SegmentedERC6551Bytecode
} from './types'

import {
Expand Down Expand Up @@ -77,4 +78,5 @@ export type {
TBImplementationVersion,
MultiCallTx,
Call3,
SegmentedERC6551Bytecode
}
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export * from './addresses'
export * from './anvilAccount'
export * from './contractABIPair'
export * from './operations'
export * from './erc1155Bytecode'
export * from './erc6551Bytecode'
export * from './messages'
export * from './multicall'
export * from './params'
Expand Down
Loading

0 comments on commit 8af4e39

Please sign in to comment.