Ton
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.
const provider = window.bitkeep.ton;
Wallet Standard
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)walletSwitchChain
- (network) => void: Switch chainsignTransaction
- (data) => object: Sign a transactiondisconnect
- () => void: Disconnect
Support version
Platform | Version |
---|---|
Chrome Extension | >=v2.4.1 |
App(IOS) | >= 8.10.0 |
App(Android) | >= 8.10.0 |
Provider
window.bitkeep.ton
Account
Get Account
send('ton_requestAccounts'): Promise<[ string // current ton address ]>
Get Balance
send("ton_getBalance", address?: string): Promise<string>
Account Change Event
// The type of the callback function triggered when accounts change interface AccountsChangedCallback { (accounts: string[]): void; // Receives an array of new account addresses } // The interface representing a provider that emits the 'accountsChanged' event interface EthereumProvider { on(event: 'accountsChanged', callback: AccountsChangedCallback): void; } provider.on('accountsChanged', (accounts) => { console.log("New accounts:", accounts); });
Try It
Loading live editor...
Network
mainnet
or testnet
Get Chain
send( "ton_getChain"): Promise<ChainName: string>
Switch Network
send("wallet_switchChain", "mainnet"): Promise<void>;
On NetworkChange
// Callback type for chainChanged event type ChainChangedCallback = (chainId: string) => void; // Interface for provider event listening interface TonProvider { on(event: "chainChanged", callback: ChainChangedCallback): void; }
Try It
Loading live editor...
Send Transaction
const seqNo = provider.send("ton_sendTransaction", [ { to: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", value: "10000", // 10000 nanotons = 0.00001 TONs data: "dapp for bitget", dataType: "text", }, ]);
Last updated on