Skip to content
Terra WalletDevelopers

Early access. The Terra API and SDKs may change before launch, and the SDK packages are not published yet.

View as Markdown

Get started

Early access

Quick start

Four steps from zero to a test payment. Every request below follows the v1 contract.

1. Get test keys#

Sign in at dashboard.terrawallet.us, create a project and create two test keys:

  • a secret key (tw_test_sk_...) for your server. It is shown once; store it in your secrets manager;
  • a publishable key (tw_test_pk_...) for the browser, only if you use the front-end widgets. It works only on the https origins you allow for the project.

Test keys only touch testnets. See Authentication.

Shell

# Keep the secret key out of your code and out of git.export TERRA_SECRET_KEY="tw_test_sk_..."

2. Create a payment intent on your server#

Send the amount as a decimal string, the fiat currency, the assets you accept and an Idempotency-Key, so a retry never creates a second payment.

Shell

curl https://terrawallet.us/api/v1/payment_intents \  -H "Authorization: Bearer $TERRA_SECRET_KEY" \  -H "Content-Type: application/json" \  -H "Idempotency-Key: order-1042-checkout" \  -d {    "amount": "120.00",    "currency": "USD",    "accepted_assets": [      { "chain": "tron", "symbol": "USDT", "contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "decimals": 6 },      { "chain": "base", "symbol": "USDC", "contract": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "decimals": 6 }    ],    "description": "Order 1042",    "metadata": { "order_id": "1042" },    "success_url": "https://shop.example.com/orders/1042/thanks",    "cancel_url": "https://shop.example.com/cart"  }

The assets above are live-mode (mainnet) contracts from Supported networks and assets. Test mode accepts testnet assets only; see Test mode.

The response carries the intent's id, its status and a checkout_url:

JSON

{  "id": "pi_...",  "status": "requires_payment",  "checkout_url": "https://pay.terrawallet.us/c/pi_...",  "amount": "120.00",  "currency": "USD",  "quotes": [    { "asset": { "chain": "tron", "symbol": "USDT", "contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "decimals": 6 },      "amount_base_units": "...", "pay_address": "...", "expires_at": "..." }  ]}

3. Send the customer to checkout#

Redirect the customer to checkout_url. They pick a network and asset and pay from their own wallet: Terra Wallet in one tap, any wallet through WalletConnect or a browser extension, or a plain address and QR code. See Hosted checkout.

4. Verify the webhook, then fulfil#

Register a webhook endpoint once (the signing secret whsec_... is shown once):

Shell

curl https://terrawallet.us/api/v1/webhook_endpoints \  -H "Authorization: Bearer $TERRA_SECRET_KEY" \  -H "Content-Type: application/json" \  -H "Idempotency-Key: webhook-endpoint-main" \  -d { "url": "https://shop.example.com/webhooks/terra",        "events": ["payment_intent.succeeded", "payment_intent.expired", "payment_intent.underpaid"] }

When payment_intent.succeeded arrives, check the Terra-Signature header against the raw body before you trust anything in it, handle each event id once, and then fulfil the order. Code for Node, Python and PHP is in Webhooks.

Next steps#