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 Ethereum-like chains.
Note that Blocto SDK for Ethereum-like chains is still in Beta. APIs are subject to breaking changes.

Installation

Install from npm/yarn
1
$ yarn add web3
2
$ yarn add @blocto/sdk
Copied!
... or via CDN
1
<script src="https://unpkg.com/@blocto/[email protected]/dist/blocto-sdk.umd.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Copied!

Usage

Initiate the Blocto provider
1
import Web3 from 'web3'
2
import BloctoSDK from '@blocto/sdk'
3
4
const bloctoSDK = new BloctoSDK({
5
ethereum: {
6
// (required) chainId to be used
7
chainId: '0x1',
8
// (required for Ethereum) JSON RPC endpoint
9
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
10
},
11
12
// (optional) Blocto app ID
13
appId: 'YOUR_BLOCTO_APP_ID',
14
});
Copied!

Blocto Provider parameters

Parameter
Type
Description
Required
ethereum.chainId
String (hex)
EVM chain ID to connect to
Reference: EVM Networks
Yes
ethereum.rpc
String
JSON RPC endpoint
Yes (only for Ethereum)
appId
String
Blocto dApp ID
No

Examples

Ethereum Mainnet
Ethereum Testnet (Rinkeby)
BSC Mainnet
BSC Testnet (Chapel)
1
const bloctoSDK = new BloctoSDK({
2
ethereum: {
3
chainId: '0x1', // 1
4
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
5
},
6
appId: 'YOUR_BLOCTO_APP_ID',
7
});
Copied!
1
const bloctoSDK = new BloctoSDK({
2
ethereum: {
3
chainId: '0x4', // 4
4
rpc: 'https://rinkeby.infura.io/v3/YOUR_INFURA_ID',
5
},
6
appId: 'YOUR_BLOCTO_APP_ID',
7
});
Copied!
1
const bloctoSDK = new BloctoSDK({
2
ethereum: {
3
chainId: '0x38', // 56
4
},
5
appId: 'YOUR_BLOCTO_APP_ID',
6
});
Copied!
1
const bloctoSDK = new BloctoSDK({
2
ethereum: {
3
chainId: '0x61', // 97
4
},
5
appId: 'YOUR_BLOCTO_APP_ID',
6
});
Copied!
Network
Chain ID
Ethereum Mainnet
1
Ethereum Rinkeby Testnet
4
BSC Mainnet
56
BSC Chapel Testnet
97
Polygon Mainnet
137
Polygon Mumbai Testnet
80001
Avalanche Mainnet
43114
Avalanche Fuji Testnet
43113
Connect to Blocto wallet Once the connection request is fired, there would be a prompt modal to guide user to register/login to Blocto wallet
1
// EIP-1193 way (recommended)
2
const accounts = bloctoSDK.ethereum.request({ method: 'eth_requestAccounts' })
3
4
// Alternative: EIP-1102 way
5
// CAVEATS! it's deprecated and may be removed from future version
6
const accounts = await bloctoSDK.ethereum.enable()
Copied!
After connected with Blocto wallet, you can start to send JSON-RPC request with blocto provider
1
// sign a message
2
bloctoSDK.ethereum.request({
3
method: 'eth_sign',
4
params: ["0xyourethaddress", "0x48656c6c6f20776f726c64"
5
] })
Copied!
Last modified 2mo ago
Copy link