link

# Connect Wallet

This applies to BitKeep, which now supports blockchains, including EVM(Ethereum、BSC、Arbitrum、Polygon、Fantom...), TRON, Solana, Terra Arweave, IOST ...

# Integrate

In order to facilitate special detection, the global object is attached with the isBitKeep attribute.

If BitKeep is not installed, we recommend that you redirect users to our website (opens new window)

# EVM

Ethereum, Binance Smart Chain, Avalanche-C, Fantom, Polygon, Arbitrum...
chainlist (opens new window) json (opens new window)

The test network is not supported for the time being. If there is no mainnet you are looking for, please Contact us (opens new window)。 to add it.

# Introduction

We provide a Simple demo (opens new window). You can also refer to MetaMask Dapp (opens new window)MetaMask Dapp demo (opens new window). We also support it.

You can also use third-party libraries in conjunction with window.bitkeep.ethereum, web3js (opens new window) ethers (opens new window)...

window.bitkeep.ethereum implementation and window.ethereum is the same. If you use a third-party library, just use window.bitkeep.ethereum replaced window.ethereum can be used to distinguish between BitKeep wallet and other wallets

# npm

# isInstalled

const isBitKeepInstalled = window.isBitKeep && window.bitkeep.ethereum;

# Provider

You can use window.bitkeep.ethereum.

function getProvider() {
  const provider = window.bitkeep && window.bitkeep.ethereum;
  if (!provider) {
    return window.open('https://bitkeep.com/download?type=0&theme=light');
  }
  return provider;
}

# eth_requestAccounts(request authorization to connect)

//if used injected
const Provider = getProvider();
const accounts = await Provider.request({ method: 'eth_requestAccounts' });
const account = accounts[0];
//if used web3
const accounts = await Provider.request({ method: 'eth_requestAccounts' });
const web3 = new Web3(Provider);
const [address] = await web3.eth.getAccounts(); // address
const chainId = await web3.eth.getChainId(); // chainId

# connected

const Provider = getProvider();
Provider.connected;

# Event listeners

used eventemitter3 (opens new window)

const Provider = getProvider();
Provider.removeAllListeners();
Provider.on('accountsChanged', ([address]) => {
  alert('address changed');
});
Provider.on('chainChanged', async (chainId) => {
  alert('chainid changed');
});

# sign

https://github.com/MetaMask/eth-sig-util

# sendTransaction(Transfer)

const Provider = getProvider();
const transactionParameters = {
  nonce: '0x00', // ignored by Bitkeep
  gasPrice: '0x09184e72a000', // customizable by user during Bitkeep confirmation.
  gas: '0x2710', // customizable by user during Bitkeep confirmation.
  to: '0x0000000000000000000000000000000000000000', // Required except during contract publications.
  from: Provider.selectedAddress, // must match user's active address.
  value: '0x00', // Only required to send ether to the recipient from the initiating external account.
  data:
    '0x7f7465737432000000000000000000000000000000000000000000000000000000600057', // Optional, but used for defining smart contract creation and interaction.
  chainId: '0x3', // Used to prevent transaction reuse across blockchains. Auto-filled by Bitkeep.
};
// txHash is a hex string
// As with any RPC call, it may throw an error
const txHash = await Provider.request({
  method: 'eth_sendTransaction',
  params: [transactionParameters],
});
// if used web3
const accounts = await Provider.request({ method: 'eth_requestAccounts' });
const web3 = new Web3(Provider);
const result = await web3.eth.sendTransaction({
  from: Provider.selectedAddress,
  to: '0x0000000000000000000000000000000000000000',
  value: web3.utils.toWei('1', 'ether'),
});

# Using open source libraries

if you have problems with third-party libraries that cannot be solved, you can c Contact us (opens new window).

# Tron

We provide Simple demo (opens new window) and are compatible with tronlink dapp (opens new window).

# isInstalled

const isBitKeepInstalled = window.tronLink && window.isBitKeep;

# eth_requestAccounts(request authorization to connect)

try {
  await tronLink.request({ method: 'tron_requestAccounts' });
  const address = tronWeb.defaultAddress.base58;
  const balance = await tronWeb.trx.getBalance(address);
} catch {}

# connected

window.tronWeb.ready;

# sendTransaction(Transfer)

var tronweb = window.tronWeb;
var tx = await tronweb.transactionBuilder.sendTrx(
  'TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw',
  1000000,
  tronWeb.defaultAddress.base58
);
var signedTx = await tronweb.trx.sign(tx);
var broastTx = await tronweb.trx.sendRawTransaction(signedTx);
console.log(broastTx);
console.log(broastTx.txid);
//Token
let decimal = 18;
let Contract = await tronWeb
  .contract()
  .at('TLa2f6VPqDgRE67v1736s7bJ8Ray5wYjU7'); //WIN
const decimalCall = Contract.decimals || Contract.DECIMALS;
if (decimalCall) {
  decimal = await decimalCall().call();
}
let broastTx = await Contract.transfer(
  'TW8u1VSwbXY7o7H9kC8HmCNTiSXvD69Uiw',
  // "0xde0b6b3a7640000"
  tronWeb.toHex(2 * Math.pow(10, decimal))
)
  .send
  // {
  //     feeLimit: 10000000
  // }
  ();
console.log(broastTx);

# solana

We provide a Simple demo (opens new window), and you can also refer to solana-web3 (opens new window)

# IsInstalled

const isBitKeepInstalled = window.isBitKeep && window.bitkeep.solana;

# Provider

function getProvider() {
  const provider = window.bitkeep && window.bitkeep.solana;
  if (!provider) {
    return window.open('https://bitkeep.com/download?type=0&theme=light');
  }
  return provider;
}

# connect(request authorization to connect)

try {
  await window.bitkeep.solana.connect();
  const publicKey = await window.bitkeep.solana.getAccount();
  window.bitkeep.solana.publicKey.toString(); // Once the web application is connected to Bitkeep,
} catch {
  alert('connected error');
}

# connected

window.bitkeep.solana.connected;
const publicKey = await window.bitkeep.solana.getAccount();
window.bitkeep.solana.publicKey.toString(); // Once the web application is connected to Bitkeep

# signMessage

//string
window.bitkeep.solana.signMessage(
  '020006106e655af38ff7324bbf1d4e16b06084763269b9'
);
// uint8Array
const message = `You can use uint8array to verify`;
const encodedMessage = new TextEncoder().encode(message);
const signedMessage = await window.bitkeep.solana.signMessage(encodedMessage);
const nacl = require('tweetnacl');
const { PublicKey } = require('@solana/web3.js');
// nacl.sign.detached.verify(encodedMessage, signedMessage, publicKey)
nacl.sign.detached.verify(
  encodedMessage,
  signedMessage,
  new PublicKey(address).toBytes()
);

# Event listeners

used eventemitter3 (opens new window)

window.bitkeep.solana.on('connect', () => console.log('connected!'));

# sendTransaction

You can refer to the following demo : simple demo (opens new window) web3 demo (opens new window) Token demo (opens new window)

# Terra

You can refer to the following simple demo (opens new window)

# WalletConnect

# EVM(WebApp)

We also support WalletConnect (opens new window). Please refer to walletconnect documentation for details. Similarly, we provide a simple demo (opens new window)

npm install --save @walletconnect/client @walletconnect/qrcode-modal
import WalletConnect from '@walletconnect/client';
import QRCodeModal from '@walletconnect/qrcode-modal';
// Create a connector
const connector = new WalletConnect({
  bridge: 'https://bridge.walletconnect.org', // Required
  qrcodeModal: QRCodeModal,
});
// Check if connection is already established
if (!connector.connected) {
  // create new session
  connector.createSession();
}
// Subscribe to connection events
connector.on('connect', (error, payload) => {
  if (error) {
    throw error;
  }
  // Get provided accounts and chainId
  const { accounts, chainId } = payload.params[0];
});
connector.on('session_update', (error, payload) => {
  if (error) {
    throw error;
  }
  // Get updated accounts and chainId
  const { accounts, chainId } = payload.params[0];
});
connector.on('disconnect', (error, payload) => {
  if (error) {
    throw error;
  }
  // Delete connector
});

# EVM(Native App SDK)

Please refer to the WalletConnect Doc (opens new window) and follow to find the docking documentation of your current program

# Bitkeep(Chrome extension swap)

Only BitKeep Chrome extension is supported for the time being

If you send an unsupported mainnet, an error will be prompted

  • # window.bitkeep.navigateTo

    invoke swap, Support Mainnet can refer to support mainnet.

    window.bitkeep.navigateTo('swap', {
        chain: "eth"
        fromCoin: {
            chain: 'eth',
            chainName: 'Ethereum',
            contract: '0xdac17f958d2ee523a2206206994597c13d831ec7',
            icon: 'https://cdn.bitkeep.vip/coins/u/usdt_eth.png',
            symbol: 'USDT',
        },
        toCoin: {
            chain: 'eth',
            chainName: 'Ethereum',
            icon: 'https://cdn.bitkeep.vip/u_b_bae388c0-9afd-11ec-aac8-bf8a172584ab.png',
            symbol: 'ETH',
        },
    });
    

    # params

    key type require default description
    fromCoin object false Current Mainnet Token Token to be swap. Refer to the following table for details
    toCoin object false Current Mainnet Token usdt/usdc Token to be converted. Refer to the following table for details
    fromCoin/toCoin type require value description
    chain string true eth "eth" =="Ethereum" Mainnet name reference json
    chainName string false Ethereum Mainnet name
    contract string false contract address token contract address
    icon string true http://cdn.bitkeep.vip/u_b_81d12c10-146e-11ec-9c06-1d0c5ac6bcb6.jpeg token icon
    symbol string true usdt token name

# Used Open source library

If you use open source code and need us to support push open source code, please Contact us (opens new window)

# FAQ

  • Multi wallet coverage problem

    Use window.bitkeep.ethereum As a provider. Use window.bitkeep.solana As a provider. It will exist together with other wallets.

      bitkeep:  window.bitkeep.ethereum
      other: window.ethereum
      bitkeep:  window.bitkeep.solana
      other: window.solana