> For the complete documentation index, see [llms.txt](https://doc.torch.finance/telegram-usd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.torch.finance/telegram-usd/technical/telegram-usd-sdk/mint-tgusd.md). Agents can also search and read this documentation through its [MCP server](https://doc.torch.finance/telegram-usd/~gitbook/mcp).

# Mint tgUSD

This guide demonstrates how to use USDT to mint tgUSD

## Step 1: Import modules & Initialize Engine Contract

```typescript
import { Address, Cell, TonClient4 } from '@ton/ton';
import { tgUSDEngine } from "@torch-finance/tgusd-sdk";

const tonClient = new TonClient4({
  endpoint: 'https://mainnet-v4.tonhubapi.com',
});

// Engine Contract
const engineAddress = Address.parse("EQBugHw3qUX71i5_mbUMYUAUnxdy513v5zKeLZdVhCp1J8xI")
const engine = provider.open(tgUSDEngine.createFromAddress(engineAddress));
```

## Step 2: Request Mint Order Payload via API

**HTTP Request**

<mark style="color:green;">`POST`</mark> `/mint`

**Request Parameters**

| Parameter           | Type   | Required | Description                                                                          |
| ------------------- | ------ | -------- | ------------------------------------------------------------------------------------ |
| `userAddress`       | String | ✅ Yes    | minter address                                                                       |
| `collateralAssetID` | String | ✅ Yes    | Asset ID of the collateral (must be generated using `Asset.ID` from Torch SDK)       |
| `collateralAmount`  | String | ✅ Yes    | The collateral amount needed for this minting process (ensure decimals are included) |

**Response Fields**

| Field              | Type   | Description                                     |
| ------------------ | ------ | ----------------------------------------------- |
| `signature`        | String | Hex-encoded signature for on-chain verification |
| `payload`          | String | Hex-encoded serialized payload                  |
| `tgUSDAmount`      | String | The amount of tgUSD to be minted                |
| `collateralAmount` | String | collateralAmount submitted by the minter        |

**Example**

```typescript
import { Asset } from '@torch-finance/core';
import { Address } from '@ton/core';
import axios from 'axios';

// Prepares mint parameters
const queryId = 8n

// Minter Address
const minterAddress = Address.parse("minter-address")

// USDT Asset
const usdtAsset = Asset.jetton(Address.parse('EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'));

// Use 0.1 USDT to mint tgUSD
const depositAmount = 100000n;

// Request mint order payload from api
const response = await axios.post('https://tgusd-api.torch.finance/mint', {
  userAddress: minterAddress.toString(),
  collateralAssetID: usdtAsset.ID,
  collateralAmount: depositAmount.toString(),
});

const { signature, payload, collateralAmount } = response.data;

```

{% hint style="warning" %}
The returned payload will expire after **300 seconds.**
{% endhint %}

## Step 3: Build Mint Payload

```typescript
const mintPayload = await engine.getMintPayload(minterAddress, {
  signature: Buffer.from(signature, 'hex'),
  order: Cell.fromHex(payload),
  collateralInfo: {
    collateralAsset: usdtAsset,
    collateralAmount: BigInt(collateralAmount),
  },
  queryId: queryId,
});

```
