Network operations
Requesting a card, topping up a card, depositing to the vault and withdrawing from it are transactions of a wallet with the contract of your program. The API does not move money. It checks the request with the rules of the panel and returns the transaction ready to sign. Your wallet signs and sends it, and the result counts when the network confirms.
The API never keeps or uses a private key. Who signs is your choice: the wallet of the person (MetaMask, WalletConnect) or wallets your company runs (ethers, viem, a custody service), with the same object.
The answer
Every route of this page answers with:
| Field | What it is |
|---|---|
onchain | The network, the chainId, the address of the vault, the token, its address and decimals, and the amounts in units of the token |
quote | What the operation costs, in dollars, when it has a cost |
calls | The transactions to sign, in order. Each one has chainId, to, data, value, method and args |
Send each item of calls as it is. To build the transaction yourself, use the data in onchain.
Who pays
The contract charges the wallet that signs, from the balance that wallet has in the contract of your program. The request does not say which wallet will sign: the contract sees it when the transaction arrives.
| Wallet that signs | When to use |
|---|---|
| An admin wallet of your company | Your company pays the cards and top-ups of its users, as in the Business panel. To pay from your server, add the address of the wallet in Web3 → Admin wallets of the panel, where an admin signs once, and keep its key on your server |
| The wallet of the person | The person pays with their own balance. Link the wallet to the account, in the app or with POST /v2/users/{id}/wallets for embedded accounts, so that its deposits and its balance show for that user |
Treat the cardRef of a card request as a secret. The contract takes the payment from whichever wallet sends the request with it, and that creates the card of that user.
A wallet gets balance in the contract with a deposit. The API does not read the network: it returns the calls even when the wallet has no balance, and then the transaction fails in the wallet. Never send tokens straight to the address of the contract: only a deposit made with these calls is credited.
Read the balance of a wallet
You read the balance in the contract itself, as you do with DeFi APIs such as 0x and Uniswap. The address of the contract is vault.address in GET /v2/vault, and onchain.vault in the answers of this page. These are read-only functions, and the values come in units of the token:
| Function | What it returns |
|---|---|
balances(wallet) | The free balance of the wallet: what it can use or withdraw |
lockedOf(wallet) | What is locked in pending requests: a card or a top-up waiting for confirmation |
pendingCosts(program, wallet) | The costs the wallet still owes. Program 0 is the contract itself (the costs of the first deposit). The number of a program gives the costs of that card program, which come out of the next request in it |
minDeposit() | The minimum deposit |
The smallest deposit a wallet can make now is pendingCosts(0, wallet) plus minDeposit(). It is the same reading the users' app does.
const vault = new ethers.Contract(data.onchain.vault, [
"function balances(address) view returns (uint256)",
"function lockedOf(address) view returns (uint256)",
"function pendingCosts(uint256, address) view returns (uint256)",
"function minDeposit() view returns (uint256)",
], provider);
const free = await vault.balances(wallet.address); // in units of the token
provider and wallet are the ones of Sign and send. A worked example, before asking for a card with a first load of 20 dollars in a token with 6 decimals:
const units = (usd) => ethers.parseUnits(String(usd), data.onchain.decimals);
const needed = units(20) + units(data.quote.maxCharges); // first load + ceiling of charges
if (free < needed) {
const missing = needed - free;
const min = await vault.minDeposit();
const costs = await vault.pendingCosts(0, wallet.address); // come out of the deposit itself
const deposit = (missing > min ? missing : min) + costs; // ask POST /v2/vault/deposits for this amount, in dollars
}
Request a card
POST /v2/cards, with an Idempotency-Key:
| Field | Meaning |
|---|---|
userId | The user who gets the card. The user needs an approved identity |
productId | Required. The card, from GET /v2/products |
name | Required. A nickname for the card, 1 to 40 characters |
firstLoad | The first load, in dollars, from the minimum of the card |
holder | Optional: user (default) or company, for a company card |
{
"success": true,
"request": {
"cardRef": "0x5f1c…9a20",
"firstLoad": 20,
"name": "Online ads",
"expiresAt": "2026-11-16T12:30:00Z",
"productId": "prd_12"
},
"userId": "user_4M8T2KX9PQ7AB",
"onchain": {
"network": "polygon",
"chainId": 137,
"vault": "0xVAULT",
"token": "USDC",
"tokenAddress": "0xTOKEN",
"decimals": 6,
"cardRef": "0x5f1c…9a20",
"firstLoad": "20000000"
},
"quote": { "currency": "USD", "cardPrice": 5, "loadPrice": 0.3, "programCostsMax": 3, "maxCharges": 8.31 },
"calls": [
{
"chainId": 137,
"to": "0xVAULT",
"data": "0x67cd2bae…",
"value": "0",
"method": "requestCard(uint256,uint256,uint256,bytes32,uint256)",
"args": ["1", "0", "20000000", "0x5f1c…9a20", "8310000"]
}
]
}
The values in the examples are examples. The prices of your program come in quote and in GET /v2/products.
Before it returns the calls, the API checks, in this order: the identity of the user (This user has not verified their identity yet.), the invite of the account (account_paused, account_revoked), the product, the person at the card issuer (cardholder_pending and the other cardholder_*), and then the program, the limit of cards and the amount.
requestis a reservation: nothing is created yet. Sign the call beforeexpiresAt, 30 minutes later. A request paid on the network after that is refused, withcard.request.rejectedand the reasonreservation_expired, and the amount goes back to the balance of the wallet in the contract.maxChargesis a ceiling: the card price, the load price and all the costs of the program, plus one cent of margin. The contract never takes more than that. The wallet that signs needs a balance in the contract of at leastfirstLoadplusmaxCharges.- The card is created when the network confirms the transaction, in a few seconds and up to about half a minute on some networks: the event
card.createdarrives, thencard.activatedwhen the card issuer confirms. A card that takes longer than usual stays inprovisioning, withdelayed: true, and needs no new payment.card.failedarrives only when support closes the request: everything it paid is recorded as credit in the account of the person, and shows increditof the user. To use that credit or get it back, talk to support. - One pending request per user. Asking again for the same user before signing returns the same reservation (the same
cardRef), with the new data.
Top up a card
POST /v2/cards/{id}/loads with {"amount": 10}. The answer has the card, onchain, quote (currency, loadPriceBps, loadPrice, programCostsMax and maxCharges) and one call, requestLoad. Nothing is reserved: the platform checks the load when it arrives from the network. The result comes in top_up.completed. A top-up that takes longer than usual shows delayed: true on the card, which keeps working. top_up.failed arrives only when the request is closed, by support or because the card can no longer receive the top-up.
Deposit to the vault
POST /v2/vault/deposits with {"amount": 100}. The answer brings two calls: approve, for the token, and deposit, for the vault.
"calls": [
{ "chainId": 137, "to": "0xTOKEN", "data": "0x095ea7b3…", "value": "0",
"method": "approve(address,uint256)", "args": ["0xVAULT", "100000000"],
"skipIfAllowanceAtLeast": "100000000" },
{ "chainId": 137, "to": "0xVAULT", "data": "0xe2bbb158…", "value": "0",
"method": "deposit(uint256,uint256)", "args": ["100000000", "5010000"] }
]
Read allowance(wallet, vault) in the token and skip approve when it is already at least skipIfAllowanceAtLeast. Whoever does not read signs both: it only costs gas.
The answer also brings quote, with minDeposit (the minimum of a deposit), vaultCostsMax and maxCosts. The first deposit of a wallet pays, once, the costs of the program for that wallet. They come out of the amount deposited, never above maxCosts, so the contract asks for an amount of at least the minimum plus those costs. When the deposit transaction is confirmed on the network, the balance is in the contract and the wallet can sign the next call.
Only a deposit made by an admin wallet of the vault counts for your company. A deposit from another wallet stays as the balance of that wallet. The result comes in vault.deposit.completed.
Withdraw from the vault
POST /v2/vault/withdrawals with {"amount": 50}. One call, withdraw. The result comes in vault.withdrawal.completed.
Cancel a pending load
POST /v2/loads/{loadId}/cancel. One call, cancelLoad. loadId is the number of the load, from the events and from the card. Only the wallet that paid can cancel, and only while the load is pending: the contract makes sure of it.
Sign and send
An example with ethers in Node.js, for a wallet your company runs. data is the answer of any route of this page, RPC_URL is your access to the network of your program, and the wallet needs a little of the coin of the network for gas:
import { ethers } from "ethers";
const res = await fetch("https://api.sandbox.creditcard/v2/vault/deposits", {
method: "POST",
headers: { Authorization: `Bearer ${W3C_API_KEY}`, "Idempotency-Key": "deposit-0001", "Content-Type": "application/json" },
body: JSON.stringify({ amount: 100 }),
});
const data = await res.json();
const provider = new ethers.JsonRpcProvider(RPC_URL);
const wallet = new ethers.Wallet(PRIVATE_KEY, provider);
for (const call of data.calls) {
if (call.skipIfAllowanceAtLeast) {
const token = new ethers.Contract(call.to, ["function allowance(address,address) view returns (uint256)"], provider);
const allowance = await token.allowance(wallet.address, data.onchain.vault);
if (allowance >= BigInt(call.skipIfAllowanceAtLeast)) continue;
}
const tx = await wallet.sendTransaction({ to: call.to, data: call.data, value: BigInt(call.value), chainId: call.chainId });
await tx.wait();
}
In the browser, the same object goes to the wallet of the person, such as eth_sendTransaction in MetaMask. The private key stays in the wallet or in your custody: the API never sees it.