钱包标准
Method | Parameters | Returns | Description |
---|---|---|---|
connect | None | Promise<{ publicKey: string; address: string }> | 连接到钱包并返回账户信息 |
account | None | Promise<string> | 获取当前钱包地址 |
isConnected | None | Promise<boolean> | 检查钱包当前是否已连接 |
network | None | Promise<string> | 获取当前网络名称或 ID |
onAccountChange | callback: (address: string) => void | void | 注册账户变化的回调函数 |
onNetworkChange | callback: (network: string) => void | void | 注册网络变化的回调函数 |
onDisconnect | callback: () => void | void | 注册断开连接的回调函数 |
signTransaction | transaction: object, options?: object | Promise<string> | 签名交易并返回签名 |
signMessage | msg: string | Promise<string> | 使用钱包签名任意消息 |
disconnect | None | Promise<void> | 断开钱包连接 |
连接Bitget钱包
Provider
const provider = window.bitkeep.aptos
Connect
返回
interface ConnectResult {
publicKey: string // your publicKey on aptos
address: string // your address on aptos
}
用法
// @return ConnectResult
const response = await provider.connect()
试一试
Loading live editor...
Get Account
Returns
interface AccountResult {
publicKey: string // your publicKey on aptos
address: string // your address on aptos
}
用法
// @return AccountResult
await provider.account()
网络
用户在与 DApp 交互时可能会更改账户,这可以通过 onAccountChange 监控。
参数
interface AptosAccountChangeCallback {
(newAccount: Account): void;
}
用法
window.bitkeep.aptos.onAccountChange((newAccount) => {
console.log(newAccount)
})
试一试
Loading live editor...
监听网络变化事件
DApp 需要确保用户连接到目标网络,因此需要获取当前网络、切换网络并监听网络变化。
用法
// Current network
let network = await window.bitkeep.aptos.network()
// event listener for network changing
window.bitkeep.aptos.onNetworkChange((newNetwork) => {
network = newNetwork // { networkName: 'Mainnet' }
})
签消息
签任意消息
参数
interface SignMessagePayload {
address?: boolean // Should we include the address of the account in the message
application?: boolean // Should we include the domain of the dapp
chainId?: boolean // Should we include the current chain id the wallet is connected to
message: string // The message to be signed and displayed to the user
nonce: string // A nonce the dapp should generate
}
返回
interface AptosSignatureOutput {
chainId: number // Aptos chain ID (1 = mainnet)
application: string // App origin URL
address: string // Wallet address (hex)
publicKey: string // Wallet public key
message: string // Message to be signed
nonce: number // Unique number to prevent replay
prefix: string // Message prefix (e.g., "APTOS")
fullMessage: string // Full message that was signed
signature: string // Signature of the full message
}
用法
// @params AptosSignatureInput
// @return AptosSignatureOutput<Promise>
provider.signMessage({ nonce: 1234034, message: 'hello bitget wallet' })
试一试
Loading live editor...
交易
签名交易
签名交易但不提交到 Aptos 区块链。返回已签名的交易,然后 DApp 提交。
Parameters
interface TransactionInput {
arguments: (string | number)[] // Parameters passed to the function
function: string // Target function to call (module::function)
type: 'entry_function_payload' // Payload type (fixed value)
type_arguments: string[] // Generic type arguments (e.g., coin type)
}
Returns
interface TransactionOutput {}
用法
// Example Transaction
const transaction = {
arguments: [address, '717'],
function: '0x1::coin::transfer',
type: 'entry_function_payload',
type_arguments: ['0x1::aptos_coin::TestCoin'],
}
// @param TransactionInput
// @returns
const signTransaction = await provider.signTransaction(transaction)
广播交易
有两种发送交易的方式,通过钱包发送或通过 dapp 发送
// send transaction by bitget wallet
const pendingTransaction = await window.bitkeep.aptos.signAndSubmitTransaction(
transaction
)
// or send transaction by dapp
const client = new AptosClient('https://testnet.aptoslabs.com')
client.waitForTransaction(pendingTransaction.hash)
Last updated on