下载

arrow_down

构建

arrow_down

更多

arrow_down
activityactivityactivityactivity
  • themelight
  • languageIcon

  • menu
Skip to Content
Zh CnDocs
Connect Wallet
教程Aptos

钱包标准

MethodParametersReturnsDescription
connectNonePromise<{ publicKey: string; address: string }>连接到钱包并返回账户信息
accountNonePromise<string>获取当前钱包地址
isConnectedNonePromise<boolean>检查钱包当前是否已连接
networkNonePromise<string>获取当前网络名称或 ID
onAccountChangecallback: (address: string) => voidvoid注册账户变化的回调函数
onNetworkChangecallback: (network: string) => voidvoid注册网络变化的回调函数
onDisconnectcallback: () => voidvoid注册断开连接的回调函数
signTransactiontransaction: object, options?: objectPromise<string>签名交易并返回签名
signMessagemsg: stringPromise<string>使用钱包签名任意消息
disconnectNonePromise<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