Developer guidesAPI integration

Deploy and Mint a Stablecoin using the TypeScript Client

Step-by-step guide for creating and minting stablecoin tokens using the ATK TypeScript Client

PREREQUISITES

Before running these commands, you need to:

  1. Platform URL - Know your ATK platform URL (e.g., https://your-platform.example.com)
  2. Deploy ATK - Have a running ATK instance (local or hosted)
  3. Sign up - Create a user account through the ATK UI with email/password
  4. Enable PINCODE - Set up PINCODE during onboarding. Manage it from Account → Wallet.
  5. Admin role - Your account must have admin role to grant system roles (Steps 3a and 3d)

Note: Your wallet address is available via ATK while signing up, or you can get it from Step 2. You'll need it for Steps 3a, 3d, 5, and 8.


Quick reference

StepWhatMethod
1Initialize ClientcreateClient
2Get user infoclient.user.me
3Set up roles & trusted issuerSee Set Up Roles guide
4Create stablecoinclient.token.create (type: "stablecoin")
5Grant token rolesSee Set Up Roles guide
6Unpause tokenclient.token.unpause
7Add collateralclient.token.updateCollateral
8Mint tokensclient.token.mint
9Verifyclient.token.holders

STEP-BY-STEP COMMANDS

Step 1: Initialize Client

Initialize the ORPC client with your platform URL and authentication token.

Client helper implementation details

Here's what the helper does behind the scenes:

Why use the helper? It handles:

  • ✅ 7 imports from different packages (@orpc/client, @orpc/client/fetch, @atk/zod/*, @orpc/server, router types)
  • ✅ Configuring 3 custom JSON serializers (bigDecimalSerializer, bigIntSerializer, timestampSerializer)
  • ✅ Setting up the RPCLink with proper headers
  • ✅ Type-safe client creation

If you don't have the helper file, you'll need to set it up manually (not recommended):

import { createORPCClient } from "@orpc/client";
import { RPCLink } from "@orpc/client/fetch";
import { bigDecimalSerializer } from "@atk/zod/bigdecimal";
import { bigIntSerializer } from "@atk/zod/bigint";
import { timestampSerializer } from "@atk/zod/timestamp";
import type { RouterClient } from "@orpc/server";
import type { router } from "@/orpc/routes/router";

const link = new RPCLink({
  url: "https://your-platform.example.com/api/rpc",
  headers: () => ({
    "x-api-key": `YOUR_API_KEY_TOKEN`,
  }),
  customJsonSerializers: [bigDecimalSerializer, bigIntSerializer, timestampSerializer],
});

const client: RouterClient<typeof router> = createORPCClient(link);

💡 Tip: Copy the client.ts file from src/examples/client.ts to your project to use the helper!


Step 2: check you're logged in

Save your wallet address - you'll need it!


Step 3: set up system roles and trusted issuer status

REQUIRED: Complete these steps to grant yourself the necessary system roles and register as a trusted issuer for collateral.

Follow the Set Up Roles guide:

  1. Grant system roles :

    • tokenManager - Required to create tokens
    • claimPolicyManager - Required to register as a trusted issuer
  2. Register as trusted issuer

    • Register your identity for the collateral claim topic

Those sections in the roles guide include the full TypeScript client calls—copy the code snippets directly to satisfy this step.

Note: Only users with admin role can grant system roles. If you don't have admin access, ask your system administrator to grant you these roles and register you as a trusted issuer.


Step 4: create a stablecoin token

Parameters:

  • type: Must be "stablecoin"
  • name: Token name (e.g., "Test USD Coin")
  • symbol: Token symbol (e.g., "TUSD")
  • decimals: Usually 6 for stablecoins (like USDC) or 18
  • countryCode: ISO country code (840 = USA, 056 = Belgium, 276 = Germany)
  • priceCurrency: ISO currency code for liability tracking (e.g., "USD", "EUR", "GBP")
  • basePrice: Token peg value using from(value, precision) helper
    • Example: from("1.00", 2) = $1.00 with 2 decimal precision
    • Used with priceCurrency for liability tracking dashboards
  • initialModulePairs: Compliance modules (empty array [] for basic setup)

Expected: Returns token data with id (contract address)

SAVE THE CONTRACT ADDRESS from the response! You need it for Step 5.


Step 5: grant token roles

REQUIRED: Grant yourself supplyManagement (for minting) and emergency (for unpausing) roles on the stablecoin contract.


Step 6: unpause the token


Step 7: add collateral (required for stablecoins)

IMPORTANT: Stablecoins require collateral before minting. You must complete Step 3 first to register as a trusted issuer for the collateral claim topic (see Set Up Roles guide Step 4).

Parameters:

  • amount: Collateral amount in smallest unit (e.g., 1000000000000n = 1,000,000 tokens with 6 decimals)
  • expiryTimestamp: Future date when collateral expires

Expected: Returns token data with updated collateral

Note: If you get an error about not being a trusted issuer, follow the Set Up Roles guide Step 4 to register as a trusted issuer for the collateral claim topic.


Step 8: mint stablecoins

Parameters:

  • contract: Your stablecoin contract address
  • recipients: Array with recipient wallet address(es)
  • amounts: Array with amounts in smallest unit
    • To mint X tokens with 6 decimals, use: X * 10^6
    • Example: 1 * 10^6 = 1 TUSD
    • Example: 1000 * 10^6 = 1000 TUSD
    • For 18 decimals: X * 10^18 (e.g., 1 * 10^18 = 1 token)

Expected: Returns token data with updated totalSupply


Step 9: verify the mint

Expected: Shows token holders with their balances


FULL SCRIPT

Complete working script - Replace the variables at the top (YOUR_PLATFORM_URL, YOUR_AUTH_TOKEN, YOUR_PINCODE) and run:

Important:

  • This script references the Set Up Roles guide for Step 3 (role management)
  • Step 3 in the script is a placeholder comment—you must complete the role setup steps manually before continuing
  • It assumes you have admin role to grant system roles. If you don't have admin access, you'll need your system administrator to grant you the tokenManager and claimPolicyManager roles, and register you as a trusted issuer for collateral

Common country codes

  • 840 = USA
  • 056 = Belgium
  • 276 = Germany
  • 826 = UK
  • 392 = Japan

Amount calculations

For stablecoins with 6 decimals (like USDC), use the formula: amount * 10^6

Examples:

  • 1 TUSD = 1 * 10^6 = 1000000
  • 10 TUSD = 10 * 10^6 = 10000000
  • 100 TUSD = 100 * 10^6 = 100000000
  • 1000 TUSD = 1000 * 10^6 = 1000000000

For tokens with 18 decimals, use the formula: amount * 10^18

Examples:

  • 1 token = 1 * 10^18 = 1000000000000000000
  • 10 tokens = 10 * 10^18 = 10000000000000000000

To mint X tokens, calculate: X * 10^decimals (where decimals = 6 for stablecoins like USDC, or 18 for other tokens)


Troubleshooting

"Authentication missing" → Run Step 1 again (sign in)

"PINCODE_INVALID" → Reconfirm the PIN from Account → Wallet (/account/wallet)

"USER_NOT_AUTHORIZED" / "tokenManager required" → Follow the Set Up Roles guide Step 2 to grant the tokenManager system role

"Permission denied" → Follow the Set Up Roles guide Step 4 to grant token roles

"Token is paused" → Make sure Step 6 (unpause) succeeded and you have emergency role

"InsufficientCollateral" → Make sure Step 7 (add collateral) succeeded. You must be a trusted issuer for the collateral claim topic.

"You are not a trusted issuer for topic(s): collateral" → Follow the Set Up Roles guide Step 4 to register as a trusted issuer for the collateral claim topic

"RecipientNotVerified" → Your wallet needs an identity registered before it can receive tokens. Follow the Set Up Roles guide Step 3 to register your identity.

Need jq? Install with: brew install jq (Mac) or apt install jq (Linux)

On this page