# FAQs

# FAQs about Bitget Chrome Extension

Note

Please always use window.bitkeep.ethereum as the constant provider when connecting to Bitget Wallet.

# 1. If it fails to detect the window?.bitkeep?.ethereum program

If it fails to detect the window?.bitkeep?.ethereum program, the developer may guide the user to go to web3.bitget.com to download the extension (opens new window)

For instance:


 







function getProvider() {
    const provider = window.bitkeep && window.bitkeep.ethereum;
    if (!provider) {
        window.open('https://web3.bitget.com/en/wallet-download?type=2');
        throw "Please go to our official website to download!!"
    }
    return provider;
}
1
2
3
4
5
6
7
8

# 2. Overwriting and other conflicts

Many DApps use window.ethereum when connecting to BitKeep Chrome Extension, which causes overwriting and other conflicts, making users confused. Solution:

Note

Please use window.bitkeep.ethereum to connect to Bitget Chrome Extension. It shares the same features as web3.currentProvider window.ethereum program. Please refer to the following sample code for more than one wallet

# 3. Address conflicts when switching network

Note

Please clear the current wallet listening event before switching network.

For instance:













































 





 






















 



 







 


 





































<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- <script src="./js/web3.min.js"></script> -->
    <script src="https://cdn.bootcdn.net/ajax/libs/web3/1.8.0/web3.min.js"></script>
  </head>
  <style>
    * {
      margin: 0;
      padding: 0;
      list-style: none;
    }
  </style>
  <body>
    <div>
      <button id="bitKeepConnect">BitKeep</button>
      <button id="injectedConnect">injected</button>
      <div>
        <span id="address"></span>
        <span id="chainId"></span>
      </div>
    </div>
    <div>
      <button id="eth_signTypedData_v4">eth_signTypedData_v4</button>
    </div>
    <script>
      let bitKeepBtn = document.querySelector("#bitKeepConnect"),
        injectedBtn = document.querySelector("#injectedConnect"),
        ethSignTypedDataV4Btn = document.querySelector("#eth_signTypedData_v4"),
        addressSpan = document.querySelector("#address"), 
        chainIdSpan = document.querySelector("#chainId");
      let provider = null,
        web3 = null;
      function getProvider(type) {
        let provider = null;
        if (type == "bitkeep") {
          provider = window.bitkeep && window.bitkeep.ethereum;
          if (!provider) {
            window.open("https://web3.bitget.com/en/wallet-download?type=0&theme=light");
            throw "please install BitKeep";
          }
        } else {
          provider = window.ethereum;
          if (!provider) {
            throw "please install injected wallet";
          }
        }
        return provider;
      }
      //address  and chanId changed event
      async function accountsChanged(accounts) {
        console.log("address, isBitKeep:", !!provider.isBitKeep, accounts);
        const [address] = await web3.eth.getAccounts();
        addressSpan.innerText = address;
      }
      async function chainChanged(chainId) {
        console.log("chainChanged,isBitKeep", !!provider.isBitKeep, chainId);
        chainIdSpan.innerText = await web3.eth.getChainId();
      }
      async function connect(type = "bitkeep") {
        const lastProvider = provider;
        const newProvider = getProvider(type);
        await newProvider.request({ method: "eth_requestAccounts" });
        //1. Prevent logical conflicts. clear the last wallet listening event.
        if (lastProvider) {
          provider.removeAllListeners();
        }
        //2. The authorized link successfully replaces the wallet's providers
        provider = newProvider;
        web3 = new Web3(provider);
        // 3. event listener  address and chainId changed.  If the address does not exist, it is disconnected
        provider.on("accountsChanged", async (accounts) => {
          accountsChanged(accounts);
        });
        provider.on("chainChanged", async (chainId) => {
          chainChanged(chainId);
        });
        //4. Get the current address and chainId
        accountsChanged();
        chainChanged();
        //5.  Cache the default link and go to the wallet
        localStorage.setItem("injected", type);
      }
      //connect
      async function bitKeepBtnClick() {
        await connect("bitkeep");
        injectedBtn.style.backgroundColor = "transparent";
        bitKeepBtn.style.backgroundColor = "blue";
      }
      async function injectedBtnClick() {
        await connect("metaMask");
        bitKeepBtn.style.backgroundColor = "transparent";
        injectedBtn.style.backgroundColor = "blue";
      }
      async function ethSignTypedDataV4BtnClick() {
        const [address] = await web3.eth.getAccounts();
        // provider.request({method:"personal_sign",params:[address  ,"Hello world"]})
        const sign = await web3.eth.personal.sign(web3.utils.utf8ToHex("Hello world"), address);
      }
      bitKeepBtn.onclick = bitKeepBtnClick;
      injectedBtn.onclick = injectedBtnClick;
      ethSignTypedDataV4Btn.onclick = ethSignTypedDataV4BtnClick; // Call up signatur
      localStorage.injected &&  itKeepBtnClick(localStorage.injected);
      //
    </script>
  </body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125

# 4. Difficulties in using third-party npm packages to connect

Note

When you are using a third-party npm package, please use window.bitkeep.ethereum as the provider.

The latest release of the package allows you to connect via the MetaMask interface. The latest code distinguishes different wallets but is not released yet. You have two options for this problem:

web3modal forked in the following way supports the existence of multiple wallets

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
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

The next version of the package will support Bitget Wallet but it is yet to be released. For quick support, please refer to the demo (opens new window) (opens new window)wagmi-bitkeep-react (opens new window) we provide.

Note

ethers.js mounts the _ethers object in a window by default. It’s not recommended that you use window. _ethers Bitget Wallet also injects the _ethers object by default to avoid conflicts caused by loading sequence. Refer to the following way to import and use.

//import
import ethers from "ethers"
const ethers = rquire("ethers")
//cdn
window.ethers
1
2
3
4
5
6

# 5. Aptos has switched to Mainnet

network

We support network: Mainnet | Devnet

Testnet has been modified to Mainnet

Aptos network switching can be tested by Devnet

Last Updated: 8/31/2023, 7:45:11 PM