Comment on page
Provider
A thin JSON-RPC wrapper for interacting with chains and Blocto wallet.
Blocto SDK comes with an EIP-1193 compatible provider, you can use it to interact with EVM-compatible chains.
Note that Blocto SDK for EVM-compatible chains is still in Beta. APIs are subject to breaking changes.
Install from npm/yarn/pnpm
npm
yarn
pnpm
npm i @blocto/sdk
yarn add @blocto/sdk
pnpm add @blocto/sdk
... or via CDN
<script src="https://unpkg.com/@blocto/sdk" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
import BloctoSDK from '@blocto/sdk'
const bloctoSDK = new BloctoSDK({
ethereum: {
// (required) chainId to be used
chainId: '0x1',
// (required) JSON RPC endpoint
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
},
// (optional) Blocto app ID
appId: 'YOUR_BLOCTO_APP_ID',
});
Parameter | Type | Description | Required |
---|---|---|---|
ethereum.chainId | String (hex)
Number | EVM chain ID to connect to | Yes |
ethereum.rpc | String | JSON RPC endpoint | Yes |
appId | String | Blocto dApp ID | No |
Ethereum Mainnet
Ethereum Testnet (Goerli)
BSC Mainnet
BSC Testnet (Chapel)
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x1', // 1
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
},
appId: 'YOUR_BLOCTO_APP_ID',
});
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x5', // 5
rpc: 'https://rpc.ankr.com/eth_goerli',
},
appId: 'YOUR_BLOCTO_APP_ID',
});
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x38', // 56
},
appId: 'YOUR_BLOCTO_APP_ID',
});
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x61', // 97
},
appId: 'YOUR_BLOCTO_APP_ID',
});
Network | Chain ID |
---|---|
Ethereum Mainnet | 1 |
Ethereum Goerli Testnet | 5 |
Arbitrum Mainnet | 42161 |
Arbitrum Goerli Testnet | 421613 |
Optimism Mainnet | 10 |
Optimism Goerli Testnet | 420 |
Polygon Mainnet | 137 |
Polygon Mumbai Testnet | 80001 |
BSC Mainnet | 56 |
BSC Chapel Testnet | 97 |
Avalanche Mainnet | 43114 |
Avalanche Fuji Testnet | 43113 |
Once the connection request is fired, there would be a prompt modal to guide user to register/login to Blocto wallet
// EIP-1193 way (recommended)
const accounts = bloctoSDK.ethereum.request({ method: 'eth_requestAccounts' })
// Alternative: EIP-1102 way
// CAVEATS! it's deprecated and may be removed from future version
const accounts = await bloctoSDK.ethereum.enable()
After connected with Blocto wallet, you can start to send JSON-RPC request with blocto provider
// sign a message
bloctoSDK.ethereum.request({
method: 'eth_sign',
params: ["0xyourethaddress", "0x48656c6c6f20776f726c64"]
})