Wallet Aptos Usage
Install and use @tetherto/wdk-wallet-aptos for Aptos accounts, balances, transfers, and signing.
Install
npm install @tetherto/wdk-wallet-aptos@1.0.0-beta.2Create a Wallet Manager
import WalletManagerAptos from '@tetherto/wdk-wallet-aptos'
const wallet = new WalletManagerAptos(seedPhrase, {
provider: 'https://fullnode.mainnet.aptoslabs.com/v1',
transferMaxFee: 100000n
})
const account = await wallet.getAccount(0)
const address = await account.getAddress()Manage Accounts
const first = await wallet.getAccount(0)
const second = await wallet.getAccount(1)
const custom = await wallet.getAccountByPath("5'/0'/0'")
console.log(await first.getAddress())
console.log(await second.getAddress())
console.log(await custom.getAddress())getAccount(index) maps to m/44'/637'/index'/0'/0'.
Read Balances
const aptBalance = await account.getBalance()
console.log('APT balance in octas:', aptBalance)
const usdtMetadataAddress =
'0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b'
const usdtBalance = await account.getTokenBalance(usdtMetadataAddress)
console.log('USDT balance:', usdtBalance)Read-only accounts support the same balance reads without a seed phrase.
import { WalletAccountReadOnlyAptos } from '@tetherto/wdk-wallet-aptos'
const readOnlyAccount = new WalletAccountReadOnlyAptos('0x...', {
provider: 'https://fullnode.mainnet.aptoslabs.com/v1'
})
const balance = await readOnlyAccount.getBalance()An address-only account can read balances and track transactions. Fee quotes and message verification also need the matching Ed25519 public key. Use account.toReadOnlyAccount() when possible; the returned account includes it.
Send Native APT
const nativeFeeReviewThreshold = 100000n
const quote = await account.quoteSendTransaction({
to: '0x...',
value: 100000000n
})
console.log('Estimated fee in octas:', quote.fee)
if (quote.fee >= nativeFeeReviewThreshold) {
throw new Error('Native APT fee needs additional user review')
}
const result = await account.sendTransaction({
to: '0x...',
value: 100000000n
})
console.log('Transaction hash:', result.hash)
console.log('Fee in octas:', result.fee)sendTransaction() submits a native APT transfer through 0x1::aptos_account::transfer.
This quote is an advisory preflight, not an enforced fee cap. sendTransaction() builds and simulates the transfer again and exposes no native maximum-fee argument, so its gas inputs can differ from the earlier quote. Beta.2 cannot enforce a hard application limit for native APT sends.
Transfer Fungible Assets
Use the fungible asset metadata address as token.
const quote = await account.quoteTransfer({
token: usdtMetadataAddress,
recipient: '0x...',
amount: 1000000n
})
console.log('Estimated fee in octas:', quote.fee)
const result = await account.transfer({
token: usdtMetadataAddress,
recipient: '0x...',
amount: 1000000n
})
console.log('Transfer hash:', result.hash)
console.log('Fee in octas:', result.fee)transfer() submits 0x1::primary_fungible_store::transfer and can auto-create the recipient primary store.
When configured, transferMaxFee applies to this fungible asset flow only. transfer() rejects an estimated fee at or above the cap.
Sign and Verify Messages
const message = 'Hello, Aptos'
const signature = await account.sign(message)
const readOnly = await account.toReadOnlyAccount()
const valid = await readOnly.verify(message, signature)
console.log('Signature valid:', valid)Sign Native APT Transfers Without Broadcasting
signTransaction() simulates and signs a native APT transfer without broadcasting it. It still calls the configured fullnode for account sequence, gas, chain, and simulation data.
const signed = await account.signTransaction({
to: '0x...',
value: 100000000n
})Treat the signed transaction as a sensitive authorization payload. Do not write it to logs, analytics, or client-visible errors.
This is not an offline operation. A failed simulation prevents signing. Fungible asset transfers are built and submitted through transfer().
transferMaxFee does not apply to native APT signing or sending. You can quote a native transfer for user review before signing or submitting:
const nativeFeeReviewThreshold = 100000n
const quote = await account.quoteSendTransaction({
to: '0x...',
value: 100000000n
})
if (quote.fee >= nativeFeeReviewThreshold) {
throw new Error('Native APT fee needs additional user review')
}signTransaction() also performs its own later simulation and exposes no native maximum-fee argument. If a product requires a hard fee cap rather than an advisory review threshold, beta.2 does not provide that control for native APT operations.
Check Transaction Status
const receipt = await account.getTransaction(result.hash)
if (receipt.finality === 'pending') {
console.log('Transaction is pending')
} else if (receipt.success === false) {
console.error('Transaction failed:', receipt.transaction.vm_status)
}getTransaction() accepts 0x plus 64 hexadecimal characters, trims surrounding whitespace, and throws NoSuchElementError while the fullnode does not know a valid hash. Pending transactions use finality: 'pending'; any committed Aptos transaction uses finality: 'final'.
Wait for commitment when your next step depends on the result:
const receipt = await account.waitForTransaction(result.hash, {
target: 'final',
timeout: 120000
})
if (receipt.success === false) {
throw new Error(`Aptos execution failed: ${receipt.transaction.vm_status}`)
}Resolution proves the requested finality, not successful execution. Always inspect success. getTransactionReceipt() remains available as a deprecated raw lookup for migrations; prefer the normalized methods in new code.
Dispose Secret Material
account.dispose()
wallet.dispose()account.dispose() clears the writable account's private-key material. wallet.dispose() disposes cached accounts and signers, but beta.2 leaves the manager's original seed buffer allocated and readable. For stronger cleanup, drop every reference to the manager and its input seed; keep seed-handling work isolated in a short-lived process or equivalent boundary when your threat model requires memory reclamation.