Integrate with Web3.js

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.

Note that Blocto SDK for EVM-compatible chains is still in Beta. APIs are subject to breaking changes.

Installation

Install from npm/yarn/pnpm

npm i web3 @blocto/sdk

Usage

Initiate Blocto SDK and Web3

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);

Blocto SDK Parameters

ParameterTypeDescriptionRequired

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

const bloctoSDK = new BloctoSDK({
    ethereum: {
        chainId: '0x1', // 1
        rpc: 'https://mainnet.infura.io/v3/YOUR_INFURA_ID',
    },
    appId: 'YOUR_BLOCTO_APP_ID',
});

You can then use the web3 object for on-chain interactions. For more documentation for what you can do with web3.js, check out

Supported Chain ID

NetworkChain ID

Ethereum Mainnet

1

Ethereum Goerli Testnet

5

Ethereum Sepolia Testnet

11155111

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

Base Mainnet

8453

Base Goerli Testnet

84531

Zora Mainnet

7777777

Zora Goerli Testnet

999

Scroll Mainnet

534352

Scroll Sepolia Testnet

534351


Last updated