> Source: https://developers.terrawallet.us/docs/quickstart . Terra Wallet developer docs (early access).

# Quick start

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

> **Preview.** The Terra API is in early access and may change before launch. The server SDKs are not published
> yet, so this guide calls the HTTP API directly.

## 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](https://developers.terrawallet.us/docs/authentication.md).

```bash
# 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.

```bash
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](https://developers.terrawallet.us/docs/networks.md). Test mode
accepts testnet assets only; see [Test mode](https://developers.terrawallet.us/docs/pay/test-mode.md).

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](https://developers.terrawallet.us/docs/pay/hosted-checkout.md).

## 4. Verify the webhook, then fulfil

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

```bash
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](https://developers.terrawallet.us/docs/webhooks.md).

## Next steps

- [Payment intents](https://developers.terrawallet.us/docs/pay/payment-intents.md): statuses, quotes and edge cases.
- [Errors](https://developers.terrawallet.us/docs/errors.md), [Idempotency](https://developers.terrawallet.us/docs/idempotency.md) and [Rate limits](https://developers.terrawallet.us/docs/rate-limits.md).
- Ask your AI assistant: connect the [Terra MCP server](https://developers.terrawallet.us/docs/ai.md) and use the prompt "Add Terra Pay checkout to
  my app".
