Connect / Disconnect
Use Blocto wallet SDK to connect Ethereum
Note that Blocto SDK for EVM-compatible chains is still in Beta. APIs are subject to breaking changes.
Install from npm/yarn
$ yarn add @blocto/sdkStep 1 - Configure Web3 and @blocto/sdk
Goerli RPC demo
import Web3 from "web3";
import BloctoSDK from "@blocto/sdk";
const bloctoSDK = new BloctoSDK({
  ethereum: {
    chainId: "0x5", // (required) chainId to be used
    rpc: `https://goerli.infura.io/v3/ef5a5728e2354955b562d2ffa4ae5305`, // (required for Ethereum) JSON RPC endpoint
  },
});
const web3 = new Web3(bloctoSDK.ethereum);
export { web3, bloctoSDK };Step 2 - Connect / Disconnect
const loginHandler = async () => {
  const accounts = await bloctoSDK.ethereum.request({
    method: "eth_requestAccounts"
  });
  setAddress(accounts[0]);
};
const logoutHandler = async () => {
  try {
    await bloctoSDK.ethereum.request({ method: "wallet_disconnect" });
    localStorage.removeItem("sdk.session");
    setAddress(null);
  } catch (error) {
    console.log(error);
  }
};Connect with prefilled email
const loginWithPrefilledEmailHandler = async () => {
  const accounts = await bloctoSDK?.ethereum?.request({
    method: "eth_requestAccounts",
    params: ["[email protected]"] // When the email is provided, the login modal will prefill the email field.
  });
  setAddress(accounts[0]);
};Sample
Last updated
Was this helpful?