Skip to main content

Get Account Resources

Returns all resources held by an account including coin balances, NFTs, and custom Move resources.

When to Use This Method​

GET /accounts/{address}/resources is essential for:

  • Balance Queries - Get all coin balances for an account
  • NFT Discovery - Find all NFTs owned by an account
  • DeFi Integration - Query liquidity positions and staked assets
  • Resource Inventory - List all Move resources an account holds

Parameters​

  1. address - string (required)

    • The account address to query
    • Format: 64 hex characters with or without 0x prefix
  2. ledger_version - string (optional)

    • Specific ledger version to query
    • If not provided, uses the latest version
  3. start - string (optional)

    • Cursor for pagination (from X-Aptos-Cursor header)
  4. limit - number (optional)

    • Maximum number of resources to return
    • Default and max values vary by node configuration

Request Example​

curl -X GET "https://api-aptos-mainnet.n.dwellir.com/v1/YOUR_API_KEY/accounts/0x1/resources" \
-H "Accept: application/json"

Response Format​

[
{
"type": "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
"data": {
"coin": {
"value": "100000000"
},
"deposit_events": {
"counter": "1",
"guid": {
"id": {
"addr": "0x1",
"creation_num": "2"
}
}
},
"withdraw_events": {
"counter": "1",
"guid": {
"id": {
"addr": "0x1",
"creation_num": "3"
}
}
},
"frozen": false
}
}
]

Implementation Examples​

import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

const config = new AptosConfig({
network: Network.MAINNET,
fullnode: "https://api-aptos-mainnet.n.dwellir.com/v1/YOUR_API_KEY",
});

const aptos = new Aptos(config);

// Get all resources for an account
async function getAccountResources(address: string) {
const resources = await aptos.getAccountResources({
accountAddress: address
});

return resources;
}

// Get specific coin balances
async function getCoinBalances(address: string) {
const resources = await aptos.getAccountResources({
accountAddress: address
});

const coinStores = resources.filter(r =>
r.type.includes("0x1::coin::CoinStore")
);

return coinStores.map(store => {
const coinType = store.type.match(/<(.+)>/)?.[1] || "unknown";
return {
coinType,
balance: store.data.coin.value,
frozen: store.data.frozen
};
});
}

// Get APT balance specifically
async function getAPTBalance(address: string): Promise<string> {
const resources = await aptos.getAccountResources({
accountAddress: address
});

const aptResource = resources.find(r =>
r.type === "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>"
);

return aptResource?.data?.coin?.value || "0";
}

// Get all NFT collections
async function getNFTCollections(address: string) {
const resources = await aptos.getAccountResources({
accountAddress: address
});

const collections = resources.filter(r =>
r.type.includes("0x3::token::Collections")
);

return collections;
}

Common Use Cases​

1. Portfolio Tracking​

Get complete portfolio of assets:

async function getPortfolio(address: string) {
const resources = await aptos.getAccountResources({
accountAddress: address
});

const portfolio = {
coins: [] as any[],
nfts: [] as any[],
defi: [] as any[],
other: [] as any[]
};

for (const resource of resources) {
if (resource.type.includes("coin::CoinStore")) {
portfolio.coins.push({
type: resource.type,
balance: resource.data.coin.value,
frozen: resource.data.frozen
});
} else if (resource.type.includes("token::")) {
portfolio.nfts.push(resource);
} else if (resource.type.includes("lending") ||
resource.type.includes("swap") ||
resource.type.includes("stake")) {
portfolio.defi.push(resource);
} else {
portfolio.other.push(resource);
}
}

return portfolio;
}

2. Multi-Token Balance Query​

Get balances for multiple token types:

interface TokenBalance {
symbol: string;
address: string;
decimals: number;
balance: string;
formattedBalance: number;
}

async function getTokenBalances(
accountAddress: string,
tokenConfigs: Array<{symbol: string, address: string, decimals: number}>
): Promise<TokenBalance[]> {
const resources = await aptos.getAccountResources({
accountAddress
});

return tokenConfigs.map(config => {
const resourceType = `0x1::coin::CoinStore<${config.address}>`;
const resource = resources.find(r => r.type === resourceType);

const balance = resource?.data?.coin?.value || "0";
const formattedBalance = Number(balance) / Math.pow(10, config.decimals);

return {
...config,
balance,
formattedBalance
};
});
}

// Usage
const balances = await getTokenBalances(
"0x123...",
[
{ symbol: "APT", address: "0x1::aptos_coin::AptosCoin", decimals: 8 },
{ symbol: "USDC", address: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC", decimals: 6 }
]
);

3. Resource Change Detection​

Monitor specific resource changes:

class ResourceMonitor {
private lastSnapshot = new Map<string, any>();

async detectChanges(address: string): Promise<any[]> {
const resources = await aptos.getAccountResources({
accountAddress: address
});

const changes = [];

for (const resource of resources) {
const lastData = this.lastSnapshot.get(resource.type);

if (!lastData) {
// New resource
changes.push({
type: "added",
resourceType: resource.type,
data: resource.data
});
} else if (JSON.stringify(lastData) !== JSON.stringify(resource.data)) {
// Modified resource
changes.push({
type: "modified",
resourceType: resource.type,
oldData: lastData,
newData: resource.data
});
}

this.lastSnapshot.set(resource.type, resource.data);
}

// Check for removed resources
for (const [type, data] of this.lastSnapshot) {
if (!resources.find(r => r.type === type)) {
changes.push({
type: "removed",
resourceType: type,
data
});
this.lastSnapshot.delete(type);
}
}

return changes;
}
}

4. Paginated Resource Fetching​

Handle large numbers of resources:

async function getAllResourcesPaginated(address: string) {
const allResources = [];
let cursor: string | undefined;

do {
const response = await fetch(
`https://api-aptos-mainnet.n.dwellir.com/v1/YOUR_API_KEY/accounts/${address}/resources` +
(cursor ? `?start=${cursor}` : ''),
{ headers: { 'Accept': 'application/json' } }
);

const resources = await response.json();
allResources.push(...resources);

// Get cursor from response header for next page
cursor = response.headers.get('X-Aptos-Cursor') || undefined;
} while (cursor);

return allResources;
}

Performance Optimization​

Resource Caching Strategy​

class ResourceCache {
private cache = new Map<string, {data: any, timestamp: number}>();
private ttl = 5000; // 5 seconds

async getResources(address: string, forceRefresh = false) {
const key = `resources:${address}`;
const cached = this.cache.get(key);

if (!forceRefresh && cached && Date.now() - cached.timestamp < this.ttl) {
return cached.data;
}

const resources = await aptos.getAccountResources({
accountAddress: address
});

this.cache.set(key, {
data: resources,
timestamp: Date.now()
});

return resources;
}

async getResource(address: string, resourceType: string) {
const resources = await this.getResources(address);
return resources.find(r => r.type === resourceType);
}
}

Error Handling​

async function safeGetResources(address: string) {
try {
const resources = await aptos.getAccountResources({
accountAddress: address
});

return {
success: true,
data: resources,
count: resources.length
};
} catch (error) {
if (error.status === 404) {
return {
success: false,
error: "Account not found",
data: []
};
}

throw error;
}
}

Need help? Contact our support team or check the Aptos documentation.