Skip to content

Ton Provider

When running a DApp in the Bitget Wallet App and in the Chrome browser with the installed Chrome Extension, you can obtain the global object window.bitkeep.ton for subsequent API calls.

js
const provider = window.bitkeep.ton;
const provider = window.bitkeep.ton;

Properties and methods of the injected objects

  • send - (payload, callback) => any: Call different methods by using different payload.method (e.g., eth_accounts, eth_coinbase, net_version, eth_chainId)
  • isConnected - () => string: Get the connection status
  • _sendAsync - (payload) => Promise: Call different chain methods by using different payload.method (e.g., ton_connect, ton_disconnect, ton_requestAccounts, ton_requestWallets, ton_getBalance, ton_sendTransaction, ton_rawSign, ton_personalSign, ton_getChain, wallet_switchChain)
  • signTypedMessage - (data) => void: Sign a Typed type message
  • signPersonalTypedMessage - (data) => void: Sign a PersonalTyped type message
  • walletSwitchChain - (network) => void: Switch chain
  • signTransaction - (data) => object: Sign a transaction
  • disconnect - () => void: Disconnect

Support version

PlatformVersion
Chrome Extension>=v2.4.1
App(IOS)>= 8.10.0
App(Android)>= 8.10.0

Connect Wallet

js
const result = await provider.send('ton_requestWallets');

result = [{
    address: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    publicKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    version: "v4R2"
}]
const result = await provider.send('ton_requestWallets');

result = [{
    address: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    publicKey: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    version: "v4R2"
}]

Get Current Account of Wallet

js
const accounts = await provider.send("ton_requestAccounts");
const account = accounts[0];
const accounts = await provider.send("ton_requestAccounts");
const account = accounts[0];

Account Change Event Listener

js
provider.on("accountsChanged", function (accounts) {
  const account = accounts[0];

  console.log("accountsChanged", accounts);
});
provider.on("accountsChanged", function (accounts) {
  const account = accounts[0];

  console.log("accountsChanged", accounts);
});

Get Current Network

mainnet or testnet

js
provider
  .send("ton_getChain")
  .then((chainId) => console.log({ chainId }))
  .catch((error) => {
    console.error(error);
  });
provider
  .send("ton_getChain")
  .then((chainId) => console.log({ chainId }))
  .catch((error) => {
    console.error(error);
  });

Switch Current Network

js
await provider.send("wallet_switchChain", "mainnet");

or;

await provider.send("wallet_switchChain", "testnet");
await provider.send("wallet_switchChain", "mainnet");

or;

await provider.send("wallet_switchChain", "testnet");

Network Change Event Listener

js
provider.on("chainChanged", (chainId) => {
  // window.location.reload();
});
provider.on("chainChanged", (chainId) => {
  // window.location.reload();
});

Get Wallet Address Balance

js
provider
  .send("ton_getBalance", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .then(handleBalance)
  .catch((error) => {
    console.error(error);
  });
provider
  .send("ton_getBalance", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  .then(handleBalance)
  .catch((error) => {
    console.error(error);
  });

Get the balance of the current address

js
provider
  .send("ton_getBalance")
  .then(handleBalance)
  .catch((error) => {
    console.error(error);
  });
provider
  .send("ton_getBalance")
  .then(handleBalance)
  .catch((error) => {
    console.error(error);
  });

Get Signature Result via ton_rawSign

js
const signature = await provider.send("ton_rawSign", [
  {
    data: "ABCDEF0123456789ABC56789ABCDEF0123456789",
  },
]);
const signature = await provider.send("ton_rawSign", [
  {
    data: "ABCDEF0123456789ABC56789ABCDEF0123456789",
  },
]);

Get Signature Result via ton_personalSign

js
const signature = await provider.send("ton_personalSign", {
  data: "Hello world",
});
const signature = await provider.send("ton_personalSign", {
  data: "Hello world",
});

Send Transaction

js
const seqNo = provider.send("ton_sendTransaction", [
  {
    to: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    value: "10000", // 10000 nanotons = 0.00001 TONs
    data: "dapp for bitget",
    dataType: "text",
  },
]);
const seqNo = provider.send("ton_sendTransaction", [
  {
    to: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    value: "10000", // 10000 nanotons = 0.00001 TONs
    data: "dapp for bitget",
    dataType: "text",
  },
]);