agentsclimarketplace

Ts sdk view and query

Skill aptos-labs/aptos-agent-skills/skills/sdk/typescript/ts-sdk-view-and-query

AI skills for building secure, modern Aptos dApps — Move contracts, TypeScript SDK, and frontend integration for Claude Code, Cursor, and Copilot.

Install
npx -y skills add aptos-labs/aptos-agent-skills --skill ts-sdk-view-and-query

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 19 stars19 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

5.5 KB, as published. Nobody here has run it

TypeScript SDK: View and Query

Purpose

Guide read-only access to chain data in @aptos-labs/ts-sdk: view functions, balance, account info, resources, and modules.

ALWAYS

  1. Use aptos.getBalance({ accountAddress }) for APT balance – not deprecated getAccountCoinAmount / getAccountAPTAmount.
  2. Use aptos.view() for Move view functions – pass function, functionArguments, and optional typeArguments.
  3. Use bigint for u128/u256 view return values – cast result[0] to BigInt(...) when the Move function returns u128/u256.
  4. Pass address as string or AccountAddress – SDK accepts AccountAddressInput (string or AccountAddress).

NEVER

  1. Do not use deprecated getAccountCoinAmount or getAccountAPTAmount – use getBalance().
  2. Do not use number for u128/u256 – precision loss; use bigint.
  3. Do not assume view returns are always strings – types vary (number, bigint, string, boolean, array).

getBalance (APT)

const balance = await aptos.getBalance({
  accountAddress: account.accountAddress
});
// balance is bigint in octas (1 APT = 100_000_000 octas)
const apt = balance / 100_000_000n;
const remainder = balance % 100_000_000n;
console.log(`${apt}.${remainder.toString().padStart(8, "0")} APT`);

getAccountInfo

const accountInfo = await aptos.getAccountInfo({
  accountAddress: "0x1"
});
// accountInfo: { sequence_number, authentication_key, ... }

view() – Move view functions

// No type arguments
const result = await aptos.view({
  payload: {
    function: `${MODULE_ADDRESS}::counter::get_count`,
    functionArguments: [accountAddress]
  }
});
const count = Number(result[0]);

// With type arguments (e.g. coin type)
const balanceResult = await aptos.view({
  payload: {
    function: "0x1::coin::balance",
    typeArguments: ["0x1::aptos_coin::AptosCoin"],
    functionArguments: [accountAddress]
  }
});
const coinBalance = BigInt(balanceResult[0] as string);

// Multiple return values
// Move: public fun get_listing(addr): (address, u64, bool)
const [seller, price, isActive] = await aptos.view({
  payload: {
    function: `${MODULE_ADDRESS}::marketplace::get_listing`,
    functionArguments: [listingAddress]
  }
});
const listing = {
  seller: seller as string,
  price: BigInt(price as string),
  isActive: isActive as boolean
};

getAccountResources

const resources = await aptos.getAccountResources({
  accountAddress: account.accountAddress
});
// resources: Array<MoveResource>
const counterResource = resources.find((r) => r.type === `${MODULE_ADDRESS}::counter::Counter`);

getAccountResource (single type)

const resource = await aptos.getAccountResource({
  accountAddress: account.accountAddress,
  resourceType: `${MODULE_ADDRESS}::counter::Counter`
});
// resource.data has the struct fields
const value = (resource?.data as { value: number })?.value;

getAccountModules

const modules = await aptos.getAccountModules({
  accountAddress: modulePublisherAddress
});
// modules: MoveModuleBytecode[] (ABI, bytecode)

getModule (single module by name)

const module = await aptos.getModule({
  accountAddress: modulePublisherAddress,
  moduleName: "counter"
});

Pagination (resources / modules)

Use cursor-based options when available:

const { resources, cursor } = await aptos.getAccountResourcesPage({
  accountAddress: account.accountAddress,
  options: { limit: 10, cursor: nextCursor }
});

Type handling for view results

Move return typeTypeScriptExample
u8..u64number or bigintNumber(result[0]) or BigInt(result[0])
u128, u256bigintBigInt(result[0] as string)
addressstringresult[0] as string
boolbooleanresult[0] as boolean
vector<T>arrayresult[0] as T[]

Common mistakes

MistakeCorrect approach
Using getAccountCoinAmountUse aptos.getBalance({ accountAddress })
Using number for u128Use BigInt(result[0] as string)
Forgetting typeArguments for generic viewAdd typeArguments: [coinType] when Move function is generic

References

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.