AgnicPay

Balance

Check your wallet USDC balance across networks

Balance

The Balance API returns your wallet's USDC balance and address information.

Endpoint

GET /api/balance

Query Parameters

ParameterTypeDefaultDescription
networkstringbase-sepoliaBlockchain network to check

Supported Networks

NetworkDescription
base-sepoliaBase testnet (for development)
baseBase mainnet (production)

Response

{
  "usdcBalance": "50.000000",
  "address": "0x1234567890abcdef1234567890abcdef12345678",
  "hasWallet": true,
  "network": "base-sepolia"
}
FieldTypeDescription
usdcBalancestringUSDC balance with 6 decimal places
addressstringYour wallet address
hasWalletbooleanWhether wallet has been created
networkstringNetwork queried

Examples

Check Default Network Balance

curl https://api.agnic.ai/api/balance \
  -H "X-Agnic-Token: agnic_tok_YOUR_TOKEN"

Check Mainnet Balance

curl "https://api.agnic.ai/api/balance?network=base" \
  -H "X-Agnic-Token: agnic_tok_YOUR_TOKEN"

Python Example

import requests
 
response = requests.get(
    "https://api.agnic.ai/api/balance",
    headers={"X-Agnic-Token": "agnic_tok_YOUR_TOKEN"},
    params={"network": "base-sepolia"}
)
 
data = response.json()
print(f"Balance: ${data['usdcBalance']} USDC")
print(f"Address: {data['address']}")

JavaScript Example

const response = await fetch(
  'https://api.agnic.ai/api/balance?network=base-sepolia',
  {
    headers: {
      'X-Agnic-Token': 'agnic_tok_YOUR_TOKEN'
    }
  }
);
 
const { usdcBalance, address } = await response.json();
console.log(`Balance: $${usdcBalance} USDC`);
console.log(`Address: ${address}`);

Check Balance Before Payment

import requests
 
def check_can_afford(amount_usd):
    response = requests.get(
        "https://api.agnic.ai/api/balance",
        headers={"X-Agnic-Token": "agnic_tok_YOUR_TOKEN"}
    )
 
    balance = float(response.json()["usdcBalance"])
    return balance >= amount_usd
 
# Check if we can afford a $0.50 payment
if check_can_afford(0.50):
    print("Sufficient balance")
else:
    print("Insufficient balance - please add funds")

Error Responses

Invalid Network

{
  "error": "invalid_network",
  "error_description": "Network 'invalid' is not supported"
}

No Wallet

{
  "usdcBalance": "0.000000",
  "address": null,
  "hasWallet": false,
  "network": "base-sepolia"
}

On this page