#!/usr/bin/env bash
set -euo pipefail
# This script requires the installation of:
# - jq (https://stedolan.github.io/jq/)
# - uuidgen (https://www.gnu.org/software/coreutils/uuidgen)
# Your API Key
API_KEY=''
# The IRON API Base URL. Currently set to sandbox.
BASE_URL="https://api.sandbox.iron.xyz/api"
# Helper to generate idempotency keys (requires uuidgen installation)
gen_key(){ uuidgen || echo "key-$RANDOM"; }
echo "Create Customer:"
IDEMPOTENCY_KEY=$(gen_key)
create_resp=$(curl -sSf \
-X POST "$BASE_URL/customers" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"customer_type":"Person",
"email":"alice@example.com",
"name":"Alice Example"
}')
customer_id=$(echo "$create_resp" | jq -r '.id')
echo "Get the first Unsigned Documents:"
unsigned_documents=$(curl -sSf -X GET "${BASE_URL}/customers/${customer_id}/unsigned-documents" \
-H "X-API-Key: $API_KEY" \
-H "Accept: application/json")
# There may be multiple unsigned documents. For simplicity, we just take the first one.
unsigned_id=$(echo "$unsigned_documents" | jq -r '.items[0]["id"]')
echo "Sign Document:"
IDEMPOTENCY_KEY=$(gen_key)
signing_resp=$(curl -sSf \
-X POST "$BASE_URL/customers/$customer_id/signings" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"signed":true,
"document_id":"'$unsigned_id'"
}')
identification_id=$(echo "$signing_resp" | jq -r '.["id"]')
echo "Create Identification:"
IDEMPOTENCY_KEY=$(gen_key)
identification=$(curl -sSf \
-X POST "$BASE_URL/customers/$customer_id/identifications" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-H "X-API-Key: $API_KEY")
echo "IDENTIFICATION: $identification"
identification_id=$(echo "$identification" | jq -r '.["id"]')
: <<'IDENTIFICATION_RESPONSE'
"created_at":"2025-06-26T10:12:49.011195+00:00",
"id":"0197abb9-c8f2-7802-a40e-182f8d16e7b7",
"status":"Pending",
"updated_at":"2025-06-26T10:12:49.011195+00:00",
"url":"https://app.sandbox.iron.xyz/verify?Okjvl2CbD-CmHumZ9pOM8j2kFB7XX5gJevGGBYl9"
IDENTIFICATION_RESPONSE
# Only on sandbox: Approve the customer. Normally this has to be done by the customer.
# They will have to click a link in the email to verify their email address.
echo "Verifying customer..."
IDEMPOTENCY_KEY=$(gen_key)
approve_resp=$(curl -sSf \
-X POST "$BASE_URL/sandbox/identification/$identification_id" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"approved":true
}')
echo "Registering hosted Solana wallet..."
IDEMPOTENCY_KEY=$(gen_key)
wallet_resp=$(curl -sSf \
-X POST "$BASE_URL/addresses/crypto/hosted" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"customer_id":"'"$customer_id"'",
"blockchain":"Solana",
"wallet_address":"AkJmANXHHpRe8ya5dvuXLneNgkpYy8GM13mwupC6p44f",
"travel_address":"TravelRuleAddr456",
"first_name":"Alice",
"last_name":"Example"
}')
wallet_address=$(echo "$wallet_resp" | jq -r '.wallet_address')
echo "Creating autoramp (EUR → USDC)..."
IDEMPOTENCY_KEY=$(gen_key)
autoramp_resp=$(curl -sSf \
-X POST "$BASE_URL/autoramps" \
-H "Content-Type: application/json" \
-H "X-API-Key: $API_KEY" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{
"customer_id":"'"$customer_id"'",
"name":"EUR to USDC Ramp",
"source_is_third_party": true,
"source_currencies":[{"type":"Fiat","code":"EUR"}],
"destination_currency":{"type":"Crypto","blockchain":"Solana","token":"USDC"},
"recipient_account":{"type":"Crypto","chain":"Solana","address":"'"$wallet_address"'"}
}')
autoramp_id=$(echo "$autoramp_resp" | jq -r '.id')
# 4. List all transactions for that autoramp
echo "4) Listing transactions for autoramp $autoramp_id..."
curl -sSf \
-X GET "$BASE_URL/autoramp-transactions?autoramp_id=$autoramp_id" \
-H "X-API-Key: $API_KEY" \
| jq .