Mint tgUSD

This guide demonstrates how to use USDT to mint tgUSD

Step 1: Import modules & Initialize Engine Contract

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

POST /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

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;

Step 3: Build Mint Payload

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

Last updated