Comment on page
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/sdk
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/${YOUR_INFURA_ID}`, // (required for Ethereum) JSON RPC endpoint
},
});
const web3 = new Web3(bloctoSDK.ethereum);
export { web3, bloctoSDK };
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);
}
};
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]);
};
Last modified 4d ago