ThaiChain
Back to home

ThaiChain Documentation

Complete guide for interacting with ThaiChain using Foundry Cast. Learn how to query blocks, transactions, tokens, and manage fees.

Network Information

Chain ID
7
RPC Endpoint
https://rpc.thaichain.org

Table of Contents

01. Install Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust. castis Foundry's command-line tool for interacting with EVM smart contracts, sending transactions, and getting chain data.

Install via foundryup

Bash — macOS / Linux
curl -L https://getfoundry.sh/install | bash

After installation, restart your terminal and run:

Bash
foundryup

Verify Installation

Bash
cast --version
cast 1.0.0 (abc1234 2026-07-16T00:00:00.000000000Z)

Note: Foundryup will automatically install the latest version of Foundry. For more details, visit the official Foundry installation guide.

02. Setup

Common Variables

Bash
# RPC endpoint
RPC=https://rpc.thaichain.org

# Token addresses
TUSD=0x20C0000000000000000000000000000000000000
FEE_MANAGER=0xfeEC000000000000000000000000000000000000

# Addresses
ADMIN=0x5266Dfa5ae013674f8FdC832b7c601B838D94eE6
RECIPIENT=0xC3317062E170f5794825dC5D93D6b045f06Bf3a5

# Private key (store as env variable)
export PRIVATE_KEY=<your_private_key>

Key Addresses

AddressNameRole
0x20C0...0000TUSD (pathUSD)Primary gas token
0xfeEC...0000FeeManagerFee collection + AMM swap
0x...TIP20FactoryCreate new tokens
0x...StablecoinDEXDEX for swapping
0x...ValidatorConfigV2Manage validators

03. View Blocks

View Block by Number

Bash
cast block 0 --rpc-url $RPC
cast block 1 --rpc-url $RPC
cast block 2499 --rpc-url $RPC

View Latest Block

Bash
cast block latest --rpc-url $RPC

View Latest Block Number

Bash
cast block-number --rpc-url $RPC

Example Output (Block 0 — Genesis)

baseFeePerGas        20000000000
difficulty           0
extraData            0x004a41ac...  ← DKG outcome
gasLimit             500000000
gasUsed              0
hash                 0xd805899e...
nonce                0x0000000000000042
number               0
timestamp            0 (Thu, 1 Jan 1970 00:00:00 +0000)
transactions:        []

Example Output (Block 1)

baseFeePerGas        10000000000
hash                 0xff4f3e71...
number               1
timestamp            1768553441 (Fri, 16 Jan 2026 08:50:41 +0000)
transactions:        [0x7f009a03...]
consensusContext     {"epoch":0,"view":1,"proposer":"0x5072dc4a..."}
timestampMillis      1768553441078

04. View Transactions

View Transaction Details

Bash
cast tx 0xec5f196f6574b488bed5b9b72edd8aee97b77d99b8f370130f47906a8973e51f --rpc-url $RPC

Example Output

blockHash            0x789c416c...
blockNumber          2499
from                 0x5266Dfa5ae013674f8FdC832b7c601B838D94eE6
to                   0xfeEC000000000000000000000000000000000000
hash                 0xec5f196f...
type                 2 (EIP-1559)
nonce                2
gasLimit             24040
effectiveGasPrice    10000000001
maxFeePerGas         20000000001
maxPriorityFeePerGas 1
input                0xa6c07924...
value                0

View Transaction Receipt

Bash
cast receipt 0xec5f196f6574b488bed5b9b72edd8aee97b77d99b8f370130f47906a8973e51f --rpc-url $RPC

05. View Token Info

TIP20 tokens have fields: name, symbol, currency, decimals, totalSupply

View Token Name

Bash
cast call $TUSD "name()(string)" --rpc-url $RPC

View Token Symbol

Bash
cast call $TUSD "symbol()(string)" --rpc-url $RPC

View Token Currency (TIP20 Extension)

Bash
cast call $TUSD "currency()(string)" --rpc-url $RPC

View Token Decimals

Bash
cast call $TUSD "decimals()(uint8)" --rpc-url $RPC

Note: TIP20 tokens always use 6 decimals (THAICHAIN-TIP21)

View Total Supply

Bash
cast call $TUSD "totalSupply()(uint256)" --rpc-url $RPC

View All at Once

Bash
echo "Name:       $(cast call $TUSD 'name()(string)' --rpc-url $RPC)"
echo "Symbol:     $(cast call $TUSD 'symbol()(string)' --rpc-url $RPC)"
echo "Currency:   $(cast call $TUSD 'currency()(string)' --rpc-url $RPC)"
echo "Decimals:   $(cast call $TUSD 'decimals()(uint8)' --rpc-url $RPC)"
echo "Total Supply: $(cast call $TUSD 'totalSupply()(uint256)' --rpc-url $RPC)"

06. View Balance

View Token Balance

Bash
cast call $TUSD "balanceOf(address)(uint256)" $ADMIN --rpc-url $RPC

Convert Balance

Bash
# View as raw value
cast call $TUSD "balanceOf(address)(uint256)" $ADMIN --rpc-url $RPC
# Output: 1000000 [1e6]

# Convert to TUSD (divide by 10^6)
# 1000000 / 10^6 = 1 TUSD

Conversion Table (6 decimals)

TUSDAmount
1 TUSD1000000
10 TUSD10000000
100 TUSD100000000
1,000 TUSD1000000000
10,000 TUSD10000000000

07. Transfer Token

Transfer TUSD

Bash
# Transfer 1 TUSD (1,000,000 units) to recipient
cast send $TUSD \
  "transfer(address,uint256)(bool)" \
  $RECIPIENT \
  1000000 \
  --private-key $PRIVATE_KEY \
  --rpc-url $RPC

Check Balance After Transfer

Bash
cast call $TUSD "balanceOf(address)(uint256)" $RECIPIENT --rpc-url $RPC

08. Mint Token

Note: You must have ISSUER_ROLE to mint tokens.

Mint TUSD to Address

Bash
# Mint 100 TUSD (100 * 10^6 = 100000000)
cast send $TUSD \
  "mint(address,uint256)" \
  $RECIPIENT \
  100000000 \
  --private-key $PRIVATE_KEY \
  --rpc-url $RPC

Mint Amount Examples

AmountCommand
1 TUSD1000000
100 TUSD100000000
1,000 TUSD1000000000

09. Fee Manager

Fee Manager precompile is located at 0xfeEC000000000000000000000000000000000000

Fee Flow

User sends transaction
    │
    ▼
collect_fee_pre_tx  → Deduct gas fee from user
    │
    ▼
Transaction executes
    │
    ▼
collect_fee_post_tx → Accumulate to collected_fees[validator][token]
    │
    ▼
distributeFees()   → Transfer accumulated fees → validator address

View Validator Accumulated Fees

Bash
# Check how much fee a validator has accumulated for a token
cast call $FEE_MANAGER \
  "collectedFees(address,address)(uint256)" \
  $ADMIN \
  $TUSD \
  --rpc-url $RPC

View Validator Fee Token

Bash
# Check which token a validator uses for fees
cast call $FEE_MANAGER \
  "validatorTokens(address)(address)" \
  $ADMIN \
  --rpc-url $RPC

Claim Accumulated Fees (Distribute Fees)

Bash
# Anyone can call — transfers accumulated fees to validator
cast send $FEE_MANAGER \
  "distributeFees(address,address)" \
  $ADMIN \
  $TUSD \
  --private-key $PRIVATE_KEY \
  --rpc-url $RPC

View FeeManager Balance

Bash
# Check how much TUSD FeeManager holds (= total accumulated fees for all validators)
cast call $TUSD \
  "balanceOf(address)(uint256)" \
  $FEE_MANAGER \
  --rpc-url $RPC

10. Decode Data

Decode Function Selector (4 bytes)

Bash
cast 4byte 0xa6c07924
# Output: distributeFees(address,address)

Decode Calldata

Bash
cast pretty-calldata 0xa6c079240000000000000000000000005266dfa5ae013674f8fdc832b7c601b838d94ee600000000000000000000000020c0000000000000000000000000000000000000

Output

Possible methods:
 - distributeFees(address,address)
 ------------
 [000]: 0000000000000000000000005266dfa5ae013674f8fdc832b7c601b838d94ee6  (validator)
 [020]: 00000000000000000000000020c0000000000000000000000000000000000000  (token)

11. Example Scripts

Check All Tokens

Bash
#!/bin/bash
RPC=https://rpc.thaichain.org
TOKENS=(
  "0x20C0000000000000000000000000000000000000"
)

for TOKEN in "${TOKENS[@]}"; do
  echo "=== Token: $TOKEN ==="
  echo "Name:       $(cast call $TOKEN 'name()(string)' --rpc-url $RPC)"
  echo "Symbol:     $(cast call $TOKEN 'symbol()(string)' --rpc-url $RPC)"
  echo "Currency:   $(cast call $TOKEN 'currency()(string)' --rpc-url $RPC)"
  echo "Decimals:   $(cast call $TOKEN 'decimals()(uint8)' --rpc-url $RPC)"
  echo "Supply:     $(cast call $TOKEN 'totalSupply()(uint256)' --rpc-url $RPC)"
  echo ""
done

Check Validator Status

Bash
#!/bin/bash
RPC=https://rpc.thaichain.org
FEE_MANAGER=0xfeEC000000000000000000000000000000000000
TUSD=0x20C0000000000000000000000000000000000000
VALIDATORS=(
  "0x5266Dfa5ae013674f8FdC832b7c601B838D94eE6"
)

for V in "${VALIDATORS[@]}"; do
  echo "=== Validator: $V ==="
  echo "Fee Token:    $(cast call $FEE_MANAGER 'validatorTokens(address)(address)' $V --rpc-url $RPC)"
  echo "Collected Fees: $(cast call $FEE_MANAGER 'collectedFees(address,address)(uint256)' $V $TUSD --rpc-url $RPC)"
  echo ""
done

References

↑ Back to top