> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dfns.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Issue stablecoins

> Deploy and manage ERC-20 stablecoins using Dfns wallets

Deploy and manage an ERC-20 stablecoin with mint, burn, and pause controls, all transactions signed and broadcast through Dfns managed wallets.

<Card title="Get the code" icon="github" href="https://github.com/dfns/dfns-solutions/tree/m/stablecoin-management">
  Clone the repository to follow along.
</Card>

Stablecoin issuers need to deploy a token contract, mint and burn supply, and freeze transfers in emergencies, all while keeping signing keys secure. This solution blueprint shows how to do that with Dfns wallets handling the key management and transaction signing. The `StableCoin` contract supports:

<Columns cols={2}>
  <Card title="Minting" icon="coins">
    Create tokens and send to any address
  </Card>

  <Card title="Burning" icon="fire">
    Destroy tokens from the caller's balance
  </Card>

  <Card title="Pausing" icon="circle-pause">
    Halt all token transfers (emergency controls)
  </Card>

  <Card title="Role-based access" icon="shield-halved">
    Restrict minting to authorized addresses via `MINTER_ROLE`
  </Card>
</Columns>

## Prerequisites

1. Clone the [stablecoin-management solution](https://github.com/dfns/dfns-solutions/tree/m/stablecoin-management)
2. Create a [Dfns organization](https://app.dfns.io) if you don't have one already, and note the organization id
3. Create a service account for API access (see how to create one [here](/guides/developers/service-account))
4. Create the "Bank" wallet on an EVM-compatible network (e.g.: Ethereum Sepolia)
5. Fund your wallet with Testnet ETH for gas fees (see [using testnets](/guides/network-testnets))
6. Make sure you have installed Node.js v18+

## Project Structure

```
contracts/
  StableCoin.sol       ERC-20 stablecoin with mint, burn, pause, and role-based access

dfns/
  DfnsCommon.ts        Shared Dfns API client and blockchain configuration
  DeployStableCoin.ts  Deploy a stablecoin contract
  StableCoinOps.ts     Interactive CLI for stablecoin operations
```

## Configuration

<Steps>
  <Step title="Clone and install">
    ```bash theme={null}
    cd stablecoin-management
    npm install
    ```
  </Step>

  <Step title="Set up environment variables">
    Copy the example environment file and fill in your values:

    ```bash theme={null}
    cp .env.example .env
    ```

    ```bash .env theme={null}
    # Dfns API Configuration
    DFNS_API_URL=https://api.dfns.io
    DFNS_ORG_ID=or-xxx-xxx
    DFNS_AUTH_TOKEN=eyJ...
    DFNS_CRED_ID=xxx
    DFNS_PRIVATE_KEY="-----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----"

    # Dfns Wallet IDs
    BANK_WALLET_ID=wa-xxx-xxx

    # Blockchain Configuration
    BLOCKCHAIN_RPC_URL=https://ethereum-sepolia-rpc.publicnode.com
    ```

    | Variable             | Description                                                                                                 |
    | -------------------- | ----------------------------------------------------------------------------------------------------------- |
    | `DFNS_API_URL`       | Dfns API base URL (`api.dfns.io`)                                                                           |
    | `DFNS_ORG_ID`        | Your Dfns organization ID. See [how to locate it](/guides/find-organization-id).                            |
    | `DFNS_AUTH_TOKEN`    | Service account auth token. Refer to [creating a service account](/guides/developers/service-account)       |
    | `DFNS_CRED_ID`       | Credential ID for the service account signing key. Find it on the dashboard, on the Service Account page.   |
    | `DFNS_PRIVATE_KEY`   | Service account private key for request signing (PEM format, including the `----BEGIN/END PRIVATE KEY----`) |
    | `BANK_WALLET_ID`     | Wallet ID for the issuer/admin role (`wa-xxxx...`)                                                          |
    | `BLOCKCHAIN_RPC_URL` | RPC endpoint for the target blockchain                                                                      |
  </Step>

  <Step title="Compile contracts">
    ```bash theme={null}
    npx hardhat compile
    ```
  </Step>
</Steps>

## Deploy

```bash theme={null}
npm run deploy
```

This deploys a `StableCoin` contract called "Bank AUD" (bAUD) with the Bank wallet as owner. The script outputs the deployed contract address.

<Tip>
  Once your contract is deployed, you can also interact with it directly from the Dfns dashboard using the **Bring Your Own ABI** feature. Import your contract's ABI and call its functions (mint, burn, pause, etc.) without any code. See the [smart contract interaction guide](/guides/smart-contracts).
</Tip>

## Manage with the Operations CLI

Use the interactive CLI to manage the deployed stablecoin:

```bash theme={null}
npm run ops <contractAddress>
```

The CLI provides these operations:

| Operation   | Description                              |
| ----------- | ---------------------------------------- |
| **Pause**   | Halt all token transfers                 |
| **Unpause** | Resume token transfers                   |
| **Mint**    | Create new tokens and send to an address |
| **Burn**    | Destroy tokens from the caller's balance |

## Example: mint, verify, burn

This walkthrough mints 100 bAUD to a destination wallet, checks the balance, burns tokens from the Bank wallet, and verifies the updated balance. The token uses 6 decimals, so 100 tokens = `100000000`.

<Steps>
  <Step title="Create a destination wallet">
    [Create a new wallet](/guides/manage-wallets) on the same network as the stablecoin contract. This wallet will receive the minted tokens. Copy its address from the dashboard.
  </Step>

  <Step title="Mint 100 bAUD">
    Run the CLI and select **Mint**, using the destination wallet address as the recipient:

    ```bash theme={null}
    npm run ops 0xYourContractAddress
    ```

    ```
    --- Smart Contract Operations ---
    1. Pause
    2. Unpause
    3. Mint
    4. Burn
    5. Exit
    Select an operation (1-5): 3
    Enter recipient address: 0xDestinationWalletAddress
    Enter amount to mint: 100000000
    Broadcasting transaction...
    Transaction broadcasted successfully!
    Transaction Hash: 0x...
    Status: Broadcasted
    ```
  </Step>

  <Step title="Check the balance">
    Open the destination wallet in the [Dfns dashboard](https://app.dfns.io). The token balance shows 100 bAUD.
  </Step>
</Steps>
