Paymentalpha
How an on-chain build is priced, paid for in ICP, and refunded.
A paid build works like a deposit. Before the build starts, you approve an amount of ICP and the canister takes the most the build could cost. When the build ends, you're charged three times what it actually used, and the rest is refunded. moxzi build --remote does all of this; you confirm the amount once.
A compiler canister whose operator hasn't set up payment builds for free, and moxzi build --remote says so.
The steps#
| Step | What happens |
|---|---|
| Quote | The canister prices the build in ICP at the current ICP/XDR rate from the Cycles Minting Canister |
| Approve | moxzi checks your balance and approves the amount with ICRC-2 (icrc2_approve) on the ICP ledger |
| Escrow | Starting the build moves the escrow to the canister |
| Build | The build runs. No further payment checks |
| Settle | The canister works out what the build used, keeps three times that (up to the escrow), and refunds the rest |
If the canister can't afford to finish the build with its own cycles, it refuses before taking any ICP.
How much#
The escrow is 750,000 cycles per byte of uploaded source, with a minimum of 0.5 trillion cycles. One trillion cycles is one XDR (about 1.3 US dollars). Most of the escrow comes back.
What a build actually used, for some real builds:
| Build | Source | Cycles used |
|---|---|---|
hello.mo | 217 bytes | about 1 billion |
| A 660-file application | 15 MB | about 1.6 trillion |
| The moxzi compiler itself | 8 MB | about 1.6 trillion |
Cost depends on the shape of the code as well as its size: code with very large functions costs more per byte.
The charge is computed from the job's own message and instruction counts, multiplied by a factor that covers memory and other costs the counts don't capture. Operators can adjust the rates.
Refunds#
| Situation | Result |
|---|---|
| The build succeeds | You pay 3× what it used, up to the escrow. The rest is refunded |
| The build fails | You pay for what it used. The rest is refunded |
| You stop driving the build and never come back | An operator can close the job and refund the unused escrow |
| The refund is smaller than the ledger fee | Nothing is transferred |
If your refund has not been sent yet, moxzi build --remote prints settlement pending and still writes your wasm. Settlement is retried until it completes and never pays out twice. Once your refund is sent, the build reports it as settled, even if the operator's share of the charge is still being processed; that part does not affect you.
Limitations#
| Limitation | |
|---|---|
| Payment is in ICP only | The canister converts to cycles itself |
| You can't get an exact price before uploading | The escrow depends on the size of what you upload |
| A local build can't predict the charge | Local instruction counts don't map to cycles at a fixed rate |