本页目录
交易
签名前先连接 provider,并确认所选网络。直接注入的 provider 与 Aptos Wallet Standard 适配器使用不同的参数类型,请勿混用示例。请替换省略的地址,并为只读请求初始化 SDK 客户端。
了解如何在 Aptos 上签署和提交交易。
签署并提交交易
// Simple APT transfer
const payload = {
type: 'entry_function_payload',
function: '0x1::aptos_account::transfer',
type_arguments: [],
arguments: [
'0x1234...', // Recipient address
'100000000', // Amount in Octas (1 APT = 100000000 Octas)
],
}
const response = await provider.signAndSubmitTransaction(payload)
console.log('Transaction hash:', response.hash)签署交易(不提交)
const payload = {
type: 'entry_function_payload',
function: '0x1::coin::transfer',
type_arguments: ['0x1::aptos_coin::AptosCoin'],
arguments: ['0x1234...', '100000000'],
}
const signedTxn = await provider.signTransaction(payload)
// Submit later using Aptos SDK
// const pendingTxn = await client.submitTransaction(signedTxn)签署交易 V2(BCS 序列化)
用于 BCS 序列化交易的高级用例:
const rawTransaction = '<BCS_SERIALIZED_TRANSACTION>'; // Use the encoding expected by your wallet version
const signedTxn = await provider.signTransactionV2({
transaction: rawTransaction,
transactionType: 'simple', // 'simple' or 'multi_agent'
asFeePayer: false,
})交易选项
const payload = {
type: 'entry_function_payload',
function: '0x1::aptos_account::transfer',
type_arguments: [],
arguments: ['0x1234...', '100000000'],
}
// The legacy direct method takes only a payload.
const response = await provider.signAndSubmitTransaction(payload)
// For gas options, use signAndSubmitTransactionV2 with the matching Wallet Standard input.智能合约交互
调用视图函数
// View functions don't require signing
const result = await client.view({
function: '0x1::coin::balance',
type_arguments: ['0x1::aptos_coin::AptosCoin'],
arguments: [accountAddress],
})
console.log('Balance:', result[0])调用入口函数
// Mint NFT example
const payload = {
type: 'entry_function_payload',
function: '0x3::token::create_collection_script',
type_arguments: [],
arguments: [
'My Collection', // Collection name
'Description', // Description
'https://example.com', // URI
'1000', // Maximum supply
[false, false, false], // Mutability config
],
}
const response = await provider.signAndSubmitTransaction(payload)多代理交易
用于需要多个签名者的交易:
const signedTxn = await provider.signTransactionV2({
transaction: rawTransaction,
transactionType: 'multi_agent',
})代付手续费交易
作为代付方签署赞助交易:
const signedTxn = await provider.signTransactionV2({
transaction: rawTransaction,
transactionType: 'simple',
asFeePayer: true,
})最后更新于