Estimate Costs and Handle Upload Payments

In this guide, you use antd, the local daemon used by the SDKs, to estimate costs, check balances, approve token spend, and choose a payment mode before you upload data.

If you want to work from the command line instead, see Use the CLI. If you want direct Rust access, see Build Directly in Rust.

Featured examples on this page use cURL, Python, Node.js / TypeScript, and Rust. Other SDK languages are available in the Language Bindings section.

Prerequisites

  • antd running on http://localhost:8082 (see Start the Local Daemon)

  • A configured wallet for write operations, or a local devnet started with ant dev start

Steps

1. Check the configured wallet

curl http://localhost:8082/v1/wallet/address
curl http://localhost:8082/v1/wallet/balance

The wallet balance response returns token balance as atto tokens and gas balance as wei.

On public EVM networks, both values matter:

  • ANT covers storage payment

  • gas covers the transaction itself

2. Approve token spend

Fresh wallets may need an approval transaction before uploads can spend tokens through the payment contracts.

This approval grants the payment contracts an unlimited token allowance.

3. Estimate storage cost

The daemon exposes cost-estimation endpoints and returns a structured estimate that includes cost, file size, chunk count, estimated gas, and the payment mode that would be used.

Use this step before uploads when you want to show a user the likely storage cost or validate that the wallet has enough balance.

4. Choose a payment mode when uploading

The daemon accepts three payment modes: auto, merkle, and single.

  • auto is the default

  • merkle forces Merkle batch payments

  • single forces per-chunk payments

For larger uploads, merkle reduces gas by using a batch payment flow.

5. Understand local versus public-network testing

On a local devnet, the test wallet is provisioned for you. On Arbitrum Sepolia or Arbitrum One, you must bring your own funded wallet.

That makes the local devnet the easiest place to verify upload payment logic before you move to a public EVM network.

Verify it worked

Check the wallet balance before and after a paid upload, then fetch the stored data by address. The upload response also tells you which payment mode the daemon actually used.

Common errors

402 Payment Required: Fund the wallet or use a local devnet.

503 Service Unavailable: The daemon does not have wallet configuration.

400 Bad Request: Check the base64 payload and payment_mode value.

Next steps

Last updated