From 4d93d48bef3d3a8e0ec6dc706f876e34581b4df0 Mon Sep 17 00:00:00 2001 From: sanyu1225 Date: Mon, 14 Oct 2024 16:07:00 +0800 Subject: [PATCH] feat: sdk init params --- package.json | 2 +- src/services/evm.ts | 30 +++++++++++++++++------------- yarn.lock | 8 ++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index fb87236..d116a49 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "dependencies": { "@blocto/dappauth": "^2.1.0", "@blocto/fcl": "^1.0.0-alpha.1", - "@blocto/sdk": "0.10.3-beta.0", + "@blocto/sdk": "0.10.4", "@chakra-ui/icons": "^1.1.1", "@chakra-ui/react": "^1.7.4", "@emotion/react": "^11", diff --git a/src/services/evm.ts b/src/services/evm.ts index 184c64b..56904b9 100644 --- a/src/services/evm.ts +++ b/src/services/evm.ts @@ -133,12 +133,16 @@ export const supportedChains = [ faucet: "https://docs.scroll.io/en/user-guide/faucet/", environment: "testnet", }, - { - name: "Linea", - chainId: "0xe708", - rpcUrls: ["https://rpc.linea.build"], - environment: "mainnet", - }, + /** + * be api (https://api.blocto.app/networks/evm) not be supported + * sdk load supported chains error + */ + // { + // name: "Linea", + // chainId: "0xe708", + // rpcUrls: ["https://rpc.linea.build"], + // environment: "mainnet", + // }, { name: "zKatana Sepolia Testnet", chainId: "0x133e40", @@ -173,21 +177,21 @@ export const supportedChains = [ }, ]; +const switchableChains = supportedChains.map((chain) => ({ + chainId: chain.chainId, + rpcUrls: chain.rpcUrls, +})); + const bloctoSDK = new BloctoSDK({ ethereum: { // (required) chainId to be used - chainId: isMainnet ? "0x1" : "0xaa36a7", - // (required for Ethereum) JSON RPC endpoint - rpc: isMainnet - ? `https://mainnet.infura.io/v3/${process.env.REACT_APP_INFURA_KEY}` - : "https://ethereum-sepolia.blockpi.network/v1/rpc/public", + defaultChainId: isMainnet ? "0x1" : "0xaa36a7", walletServer: process.env.REACT_APP_WALLET_SERVER, + switchableChains, }, appId: process.env.REACT_APP_DAPP_ID, }) as ExtendedEvmBloctoSDK; -bloctoSDK.ethereum.loadSwitchableNetwork(supportedChains); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const web3 = new Web3(bloctoSDK.ethereum); diff --git a/yarn.lock b/yarn.lock index 6b5bba8..19a33db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1407,10 +1407,10 @@ deepmerge "^4.2.2" sha3 "^2.1.4" -"@blocto/sdk@0.10.3-beta.0": - version "0.10.3-beta.0" - resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.10.3-beta.0.tgz#23f46a0a3882897d023d3a8331082df3cf5c9127" - integrity sha512-lp3HAbK7xEY/FOYDAVIS510TquqWud/tMfwDPihtpJGo74ZehFgoat7C+2HgC7S5U+RcaOyDcrvihHEWDlMBRA== +"@blocto/sdk@0.10.4": + version "0.10.4" + resolved "https://registry.yarnpkg.com/@blocto/sdk/-/sdk-0.10.4.tgz#ca78ada9961c86667423b15cda7be6459f8f2e48" + integrity sha512-tLPYS54zM6Rp5GX4QfLm9JUoxtu19kWCljLc6xwRK5zGnca4avnAqqlwowdexG1aAjU9nVyKLedig33AGLKsKg== dependencies: buffer "^6.0.3" eip1193-provider "^1.0.1"