Buy Cycles With a Card
What This Is
A cycles gateway is a canister that takes an order for cycles, has the buyer pay for it
by card on a hosted Stripe page, and delivers the cycles on-chain. icp cycles buy makes
the CLI identity the buyer: the identity that will run icp deploy creates the order
itself, so the cycles land on that identity's own cycles-ledger account and nothing has
to be linked, signed in or transferred afterwards. The agent's job is to create the
order, hand the payment link to the human, wait for delivery, and carry on deploying.
The default gateway is CyclePay, run by the DFINITY
Foundation: backend canister 2bwus-iiaaa-aaaac-bee3a-cai, mainnet only, USD only.
Everything the command quotes with is read from the gateway at run time (get_card_terms,
get_xdr_rate_status): the per-order range (USD 1 to 200 at the time of writing), the
card fee (2.9 % + 0.30 USD), the cycles-ledger delivery fee (200 M cycles) and the USD
per XDR rate (1 XDR = 1 T cycles). Do not hardcode any of them. Card details never touch
the canister or the CLI.
Prerequisites
icpCLI installed (https://cli.internetcomputer.org); load theicp-cliskill for
general usage and the -n / -e flag rule. icp cycles --help must list buy;
otherwise use the fallback below.
- A named
icpidentity for the project. The anonymous identity is refused, and the
identity that buys must be the one that deploys.
- A human who can open a URL on some device (laptop, phone). The agent's machine
needs no browser.
The Flow
# 1. Who is buying, and what they hold now
icp identity principal --identity "$ID"
icp cycles balance -n ic --identity "$ID"
# 2. Buy (spend 10 USD; or `--cycles 5t` to pay the least that buys 5 T cycles -- for a deploy,
# the gap from the `icp-cli` skill's pre-deploy estimate, N canisters × (2T + 100M) − balance)
icp cycles buy --amount 10 -n ic --identity "$ID" --no-open --yes --json
# stdout, line 1, as soon as the order exists:
# {"order_id":"co-12-…","checkout_url":"https://buy.stripe.com/…","amount":{"currency":"USD","value":"10.00"},
# "net":{"currency":"USD","value":"9.41"},"fee":{"currency":"USD","value":"0.59"},
# "estimated_cycles":"6959859171597","expires_at":"2026-10-15T18:03:12Z"}
# → show checkout_url to the user VERBATIM and ask them to pay on it (any device).
# The command polls every 3 s for up to an hour, then prints line 2 and exits 0 only on delivery:
# {"order_id":"co-12-…","status":"delivered","cycles_delivered":"6938000000000",
# "paid":{"currency":"USD","value":"10.00"},"refunded":null,"detail":null,"balance":"6938000000000"}
# 3. Continue as the same identity
icp cycles balance -n ic --identity "$ID"
icp deploy -e ic --identity "$ID"
Without --yes the command shows the quote and asks for confirmation, which needs a
terminal; without one it prints the quote and refuses (Use --yes to proceed), creating
nothing — a usable dry run when the user wants to see the figures first:
Identity: dev
Buyer: 7k7px-dcypq-wulnh-byzgd-6sib2-udn6c-lfo6e-6oujd-veifp-62woo-5ae
Gateway: 2bwus-iiaaa-aaaac-bee3a-cai (CyclePay)
Price: 10.00 USD (9.41 USD after a 0.59 USD card fee)
Estimate: about 6.959T cycles, at 1.3520 USD per 1T cycles
Flags that matter to an agent: --no-open (never let the CLI try a browser), --json
(two objects on stdout, one per line, never an array; progress and prompts go to stderr),
-q (stdout is the link, then the final status tag), --no-wait (print the link and
return; the order needs nothing more from the CLI), --gateway <canister-id> /
ICP_CYCLES_GATEWAY_CANISTER_ID (another canister serving the same interface, on any
network).
Fallback: the same order with `icp canister call`
Only when the installed CLI has no cycles buy. Same canister, same identity rules. The
argument and reply shapes are those of