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
.
fetchBalance.ts
fetch_balance.py
Response
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 );
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
.
fetchBalance.ts
fetch_balance.py
Response
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 );
It requires the following parameters:
walletLocator : The unique identifier for the wallet.
tokens : The tokens to query, such as sol
and usdc
.
fetchBalance.ts
fetch_balance.py
Response
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` , {
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 test tokens. For EVM chains, the faucet dispenses USDXM , while for Solana it dispenses 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. Use usdxm
for EVM chains and usdc
for Solana.
amount : The amount of cryptocurrency to send to the wallet.
chain : The network to use for the transaction.
fundWallet.ts
fund_wallet.py
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: 'usdxm' ,
amount: 1 ,
chain: 'base-sepolia' ,
}),
});
const data = await response . json ();
console . log ( data );
}
fundWallet (). catch ( console . error );
fundWallet.ts
fund_wallet.py
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: 'usdxm' ,
amount: 1 ,
chain: 'base-sepolia' ,
}),
});
const data = await response . json ();
console . log ( data );
}
fundWallet (). catch ( console . error );
fundWallet.ts
fund_wallet.py
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: 0.001 ,
}),
});
const data = await response . json ();
console . log ( data );
}
fundWallet (). catch ( console . error );