Crossmint’s Wallet Balance APIs allow you to retrieve and manage wallet balances efficiently across networks.

Prerequisites

Ensure you have a wallet created. You can follow the Quickstart for server wallets to prepare one. You will need:

  • API Key: Ensure you have an API key with the scopes: wallets.read, wallets:balance.read, and wallets.fund.
  • Wallet Locator: The locator of the wallet you want to fetch the balance from.

Retrieving Wallet Balances

We will use the Get Wallet Balance API.

It requires the following parameters:

  • walletLocator: The unique identifier for the wallet.
  • tokens: The tokens to query, such as eth, usdc.
  • chains: (Optional) The blockchain networks to query, such as base-sepolia, sepolia.
const walletLocator = 'your_wallet_locator';
const apiKey = 'your_api_key';

async function fetchBalance() {
    const response = await fetch(`https://staging.crossmint.com/api/v1-alpha2/wallets/${walletLocator}/balances?chains=base-sepolia,sepolia&tokens=eth,usdc`, {
        method: 'GET',
        headers: {
            'X-API-KEY': apiKey,
        },
    });

    const data = await response.json();
    console.log(data);
}

fetchBalance().catch(console.error);

Funding a Wallet

In Staging, we have a faucet that you can use to fund your wallet with USDC. Use the POST endpoint /v1-alpha2/wallets/:walletLocator/balances. It requires the following parameters:

  • walletLocator: The unique identifier for the wallet.
  • token: The token to fund the wallet with. We currently support usdc.
  • amount: The amount of cryptocurrency to send to the wallet.
  • chain: The network to use for the transaction. Only in Ethereum.
const walletLocator = 'your_wallet_locator';
const apiKey = 'your_api_key';

async function fundWallet() {
    const response = await fetch(`https://staging.crossmint.com/api/v1-alpha2/wallets/${walletLocator}/balances`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-API-KEY': apiKey,
        },
        body: JSON.stringify({
            token: 'usdc',
            amount: 1,
            chain: 'base-sepolia',
        }),
    });

    const data = await response.json();
    console.log(data);
}

fundWallet().catch(console.error);