Ton
当在 Bitget Wallet App 和安装了 Chrome 插件的浏览器中运行 DApp 时, 你可以获取全局对象 window.bitkeep.ton 来进行后续的 API 调用。
const provider = window.bitkeep.ton;
钱包标准
send
- (payload, callback) => any:通过不同的 payload.method 调用不同的方法(例如 eth_accounts、eth_coinbase、net_version、eth_chainId)isConnected
- () => string:获取连接状态_sendAsync
- (payload) => Promise:通过不同的 payload.method 调用不同链的方法(例如 ton_connect、ton_disconnect、ton_requestAccounts、ton_requestWallets、ton_getBalance、ton_sendTransaction、ton_rawSign、ton_personalSign、ton_getChain、wallet_switchChain)walletSwitchChain
- (network) => void:切换链signTransaction
- (data) => object:签名交易disconnect
- () => void:断开连接
支持的版本
Platform | Version |
---|---|
Chrome Extension | >=v2.4.1 |
App(IOS) | >= 8.10.0 |
App(Android) | >= 8.10.0 |
连接到Bitget钱包
Provider
window.bitkeep.ton
连接
使用
window.bitkeep.ton.send('ton_requestAccounts');
试一试
Loading live editor...
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);
});
试一试
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;
}
试一试
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