Skip to content

Frequently Asked Questions

1. Unable to detect bitkeep.ethereum

When window.bitkeep.ethereum is not detected, developers can guide users to the Bitget Wallet official website to download the plugin. Example code is as follows:

js
function getProvider() {
    const provider = window?.bitkeep?.ethereum;
    if (!provider) {
        window.open('https://web3.bitget.com/wallet-download?type=2');
        throw "You can guide users to download from the official website"
    }
    return provider;
}
function getProvider() {
    const provider = window?.bitkeep?.ethereum;
    if (!provider) {
        window.open('https://web3.bitget.com/wallet-download?type=2');
        throw "You can guide users to download from the official website"
    }
    return provider;
}

2. Wallet call conflict issue

Please use window.bitkeep.ethereum to connect to the Bitget Wallet Extension. It provides the same functionality as web3.currentProvider and window.ethereum.

3. Multiple wallet conflict issue

Before switching wallet connections, clear the event listeners from the previous wallet.

js
async function connect(type = "bitkeep") {
  const lastProvider = provider;
  const newProvider = getProvider(type);

  await newProvider.request({ method: "eth_requestAccounts" });

  // 1. Remove listeners from the previous wallet to prevent logic conflicts
  if (lastProvider) {
    provider.removeAllListeners();
  }

  // 2. Successfully authorize and replace the wallet providers
  provider = newProvider;
  web3 = new Web3(provider);

  // 3. Event listeners for address and chain ID changes; consider disconnection if the address does not exist
  provider.on("accountsChanged", async (accounts) => {
    accountsChanged(accounts);
  });
  provider.on("chainChanged", async (chainId) => {
    chainChanged(chainId);
  });
  // Get the current address and chainId
  accountsChanged();
  chainChanged();

  // 4. Cache the default connected wallet
  localStorage.setItem("injected", type);
}
async function connect(type = "bitkeep") {
  const lastProvider = provider;
  const newProvider = getProvider(type);

  await newProvider.request({ method: "eth_requestAccounts" });

  // 1. Remove listeners from the previous wallet to prevent logic conflicts
  if (lastProvider) {
    provider.removeAllListeners();
  }

  // 2. Successfully authorize and replace the wallet providers
  provider = newProvider;
  web3 = new Web3(provider);

  // 3. Event listeners for address and chain ID changes; consider disconnection if the address does not exist
  provider.on("accountsChanged", async (accounts) => {
    accountsChanged(accounts);
  });
  provider.on("chainChanged", async (chainId) => {
    chainChanged(chainId);
  });
  // Get the current address and chainId
  accountsChanged();
  chainChanged();

  // 4. Cache the default connected wallet
  localStorage.setItem("injected", type);
}

4. web3modal integration issue

Bitget Wallet Extension provides the following 2 solution examples:

  1. Solution for opening Bitget Wallet but unable to use: https://github.com/WalletConnect/web3modal/issues/574
  2. Use bitkeep-web3modal example code to support Bitget Wallet Extension

Integration method for multiple wallets:

js
import web3modal from 'bitkeep-web3modal';
const web3Modal = new Web3Modal({
  network: 'mainnet', // optional
  cacheProvider: true, // optional
  providerOptions: {
    bitkeep: {
      package: true,
    },
    walletconnect: {
      display: {
        logo: 'data:image/gif;base64,INSERT_BASE64_STRING',
        name: 'Mobile',
        description: 'Scan qrcode with your mobile wallet',
      },
      package: WalletConnectProvider,
      options: {
        infuraId: 'INFURA_ID', // required
      },
    },
  }, // required
});
import web3modal from 'bitkeep-web3modal';
const web3Modal = new Web3Modal({
  network: 'mainnet', // optional
  cacheProvider: true, // optional
  providerOptions: {
    bitkeep: {
      package: true,
    },
    walletconnect: {
      display: {
        logo: 'data:image/gif;base64,INSERT_BASE64_STRING',
        name: 'Mobile',
        description: 'Scan qrcode with your mobile wallet',
      },
      package: WalletConnectProvider,
      options: {
        infuraId: 'INFURA_ID', // required
      },
    },
  }, // required
});

5. ethers.js integration issue

It is not recommended to mount the _ethers object on the window using ethers.js to avoid conflicts caused by loading order.

It is recommended to use the _ethers object injected by BitKeep, and refer to the following method for usage:

js
// Directly import and use
import ethers from "ethers"
const ethers = require("ethers")
// CDN
window.ethers
// Directly import and use
import ethers from "ethers"
const ethers = require("ethers")
// CDN
window.ethers