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

6. Ton Connect High-Risk Issues

To ensure the security of Ton Connect links and prevent users from incurring financial losses, Bitget Wallet has implemented domain detection logic. The logic is as follows:

In the DApp, when invoking Bitget Wallet for authorization through Ton Connect, the Deeplink URL will include the authorization connection data.

js
https://bkcode.vip/ton-connect?
v=2&
id=xxxxx&
r={"manifestUrl":"https://mini-app.tomarket.ai/tonconnect-manifest.json","items":[{"name":"ton_addr"}]}&
ret=none
https://bkcode.vip/ton-connect?
v=2&
id=xxxxx&
r={"manifestUrl":"https://mini-app.tomarket.ai/tonconnect-manifest.json","items":[{"name":"ton_addr"}]}&
ret=none

Bitget Wallet will parse the JSON file data corresponding to the manifestUrl in the above data. The request data is as follows:

json
{
  "url": "https://mini-app.tomarket.ai",
  "name": "Tomarket",
  "iconUrl": "https://mini-app.tomarket.ai/assets/tomarket-gray-180x180.png"
}
{
  "url": "https://mini-app.tomarket.ai",
  "name": "Tomarket",
  "iconUrl": "https://mini-app.tomarket.ai/assets/tomarket-gray-180x180.png"
}

Bitget Wallet will compare the main domain of the request URL from manifestUrl with the URL in the manifest.json file.

eg:

  • manifestUrl:https://mini-app.tomarket.ai/tonconnect-manifest.json
  • URL in tonconnect-manifest.json file: https://mini-app.tomarket.ai

If the main domains of the above two links (tomarket.ai) are consistent, it will pass the check; if they are inconsistent, a warning will be displayed.