Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
getAptosClient
Retrieves an Aptos client instance from a wallet account, allowing you to interact with the Aptos blockchain.
Usage
import { getAptosClient, isAptosWalletAccount } from "@dynamic-labs-sdk/aptos";
import { getPrimaryWalletAccount } from "@dynamic-labs-sdk/client";
const walletAccount = getPrimaryWalletAccount();
if (walletAccount && isAptosWalletAccount(walletAccount)) {
const aptosClient = await getAptosClient({ walletAccount });
// Use the client to interact with the Aptos blockchain
const balance = await aptosClient.getAccountAPTAmount({
accountAddress: walletAccount.address,
});
}
React
import { getAptosClient, isAptosWalletAccount } from '@dynamic-labs-sdk/aptos';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
import { useEffect, useState } from 'react';
function AptosBalance() {
const walletAccounts = useWalletAccounts();
const walletAccount = walletAccounts.find(isAptosWalletAccount);
const [balance, setBalance] = useState(null);
useEffect(() => {
if (!walletAccount) return;
getAptosClient({ walletAccount }).then(async (client) => {
const bal = await client.getAccountAPTAmount({ accountAddress: walletAccount.address });
setBalance(bal);
});
}, [walletAccount]);
return <p>APT Balance: {balance?.toString() ?? '...'}</p>;
}
Parameters
| Parameter | Type | Description |
|---|
walletAccount | AptosWalletAccount | The wallet account to get the Aptos client for |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
Returns
Promise<AptosClient> - A promise that resolves to an Aptos client instance from @aptos-labs/ts-sdk.
Errors
| Error | Description |
|---|
NotAptosProviderError | Thrown if the wallet account’s provider is not an Aptos provider |