Skip to main content

Lovelace & Assets

This section provides assistance in gathering information regarding wallet assets and lovelace.

Other relevant functions can be found in the Wallet Extended section:

getBalance()

Return the balance in CBOR.

import { anvil } from "@ada-anvil/sdk-client";

try {
await anvil.wallet.connect("eternl");
await anvil.wallet.getBalance(); // Output: "0170334df..."
} catch {
console.log("YOUR ERROR HANDLING");
}

getBalanceByPolicies()

The function returns an object containing key-value pairs, where the key represents the policy ID, and the value represents a mapping of the asset ID to its corresponding quantity.

import { anvil } from "@ada-anvil/sdk-client";

try {
await anvil.wallet.connect("eternl");
await anvil.wallet.getBalanceByPolicies();
// Output: { "cardano" : { "lovelace": 300000000 }, "1af660e4c58514a2f0ea167deca340381e55bed4aea60bc09c211417": { "the_asset_name_03": 1 } }
} catch {
console.log("YOUR ERROR HANDLING");
}