description |
---|
Use Blocto wallet SDK with your existing web3.js integration |
You can use Blocto wallet service with your current web3.js integration with only a few simple lines of code.
{% hint style="warning" %} Note that Blocto SDK for EVM-compatible chains is still in Beta. APIs are subject to breaking changes. {% endhint %}
Install from npm/yarn/pnpm
{% tabs %} {% tab title="npm" %}
npm i web3 @blocto/sdk
{% endtab %}
{% tab title="yarn" %}
yarn add web3 @blocto/sdk
{% endtab %}
{% tab title="pnpm" %}
pnpm add web3 @blocto/sdk
{% endtab %} {% endtabs %}
import Web3 from 'web3'
import BloctoSDK from '@blocto/sdk'
const bloctoSDK = new BloctoSDK({
ethereum: {
// (required) chainId to be used
chainId: '0x1',
// (required for Ethereum) JSON RPC endpoint
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
},
// (optional) Blocto app ID
appId: 'YOUR_BLOCTO_APP_ID',
});
const web3 = new Web3(bloctoSDK.ethereum);
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 |
{% tabs %} {% tab title="Ethereum Mainnet" %}
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x1', // 1
rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
},
appId: 'YOUR_BLOCTO_APP_ID',
});
{% endtab %}
{% tab title="Ethereum Testnet (Goerli)" %}
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x5', // 5
rpc: 'https://rpc.ankr.com/eth_goerli',
},
appId: 'YOUR_BLOCTO_APP_ID',
});
{% endtab %}
{% tab title="BSC Mainnet" %}
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x38', // 56
},
appId: 'YOUR_BLOCTO_APP_ID',
});
{% endtab %}
{% tab title="BSC Testnet (Chapel)" %}
const bloctoSDK = new BloctoSDK({
ethereum: {
chainId: '0x61', // 97
},
appId: 'YOUR_BLOCTO_APP_ID',
});
{% endtab %} {% endtabs %}
You can then use the web3
object for on-chain interactions. For more documentation for what you can do with web3.js, check out
Network | Chain ID |
---|---|
Ethereum Mainnet | 1 |
Ethereum Sepolia Testnet | 11155111 |
Arbitrum Mainnet | 42161 |
Optimism Mainnet | 10 |
Polygon Mainnet | 137 |
Polygon Amoy Testnet | 80002 |
BSC Mainnet | 56 |
BSC Chapel Testnet | 97 |
Avalanche Mainnet | 43114 |
Avalanche Fuji Testnet | 43113 |
Base Mainnet | 8453 |
Zora Mainnet | 7777777 |
Scroll Mainnet | 534352 |
Scroll Sepolia Testnet | 534351 |