> 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).

# 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,
});

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.torch.finance/telegram-usd/technical/telegram-usd-sdk/mint-tgusd.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
