ThaiChain Documentation
Complete guide for interacting with ThaiChain using Foundry Cast. Learn how to query blocks, transactions, tokens, and manage fees.
Network Information
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
curl -L https://getfoundry.sh/install | bashAfter installation, restart your terminal and run:
foundryupVerify Installation
cast --versioncast 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
# 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
| Address | Name | Role |
|---|---|---|
| 0x20C0...0000 | TUSD (pathUSD) | Primary gas token |
| 0xfeEC...0000 | FeeManager | Fee collection + AMM swap |
| 0x... | TIP20Factory | Create new tokens |
| 0x... | StablecoinDEX | DEX for swapping |
| 0x... | ValidatorConfigV2 | Manage validators |
03. View Blocks
View Block by Number
cast block 0 --rpc-url $RPC
cast block 1 --rpc-url $RPC
cast block 2499 --rpc-url $RPCView Latest Block
cast block latest --rpc-url $RPCView Latest Block Number
cast block-number --rpc-url $RPCExample 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 176855344107804. View Transactions
View Transaction Details
cast tx 0xec5f196f6574b488bed5b9b72edd8aee97b77d99b8f370130f47906a8973e51f --rpc-url $RPCExample 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 0View Transaction Receipt
cast receipt 0xec5f196f6574b488bed5b9b72edd8aee97b77d99b8f370130f47906a8973e51f --rpc-url $RPC05. View Token Info
TIP20 tokens have fields: name, symbol, currency, decimals, totalSupply
View Token Name
cast call $TUSD "name()(string)" --rpc-url $RPCView Token Symbol
cast call $TUSD "symbol()(string)" --rpc-url $RPCView Token Currency (TIP20 Extension)
cast call $TUSD "currency()(string)" --rpc-url $RPCView Token Decimals
cast call $TUSD "decimals()(uint8)" --rpc-url $RPCNote: TIP20 tokens always use 6 decimals (THAICHAIN-TIP21)
View Total Supply
cast call $TUSD "totalSupply()(uint256)" --rpc-url $RPCView All at Once
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
cast call $TUSD "balanceOf(address)(uint256)" $ADMIN --rpc-url $RPCConvert Balance
# 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 TUSDConversion Table (6 decimals)
| TUSD | Amount |
|---|---|
| 1 TUSD | 1000000 |
| 10 TUSD | 10000000 |
| 100 TUSD | 100000000 |
| 1,000 TUSD | 1000000000 |
| 10,000 TUSD | 10000000000 |
07. Transfer Token
Transfer TUSD
# Transfer 1 TUSD (1,000,000 units) to recipient
cast send $TUSD \
"transfer(address,uint256)(bool)" \
$RECIPIENT \
1000000 \
--private-key $PRIVATE_KEY \
--rpc-url $RPCCheck Balance After Transfer
cast call $TUSD "balanceOf(address)(uint256)" $RECIPIENT --rpc-url $RPC08. Mint Token
Note: You must have ISSUER_ROLE to mint tokens.
Mint TUSD to Address
# Mint 100 TUSD (100 * 10^6 = 100000000)
cast send $TUSD \
"mint(address,uint256)" \
$RECIPIENT \
100000000 \
--private-key $PRIVATE_KEY \
--rpc-url $RPCMint Amount Examples
| Amount | Command |
|---|---|
| 1 TUSD | 1000000 |
| 100 TUSD | 100000000 |
| 1,000 TUSD | 1000000000 |
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 addressView Validator Accumulated Fees
# Check how much fee a validator has accumulated for a token
cast call $FEE_MANAGER \
"collectedFees(address,address)(uint256)" \
$ADMIN \
$TUSD \
--rpc-url $RPCView Validator Fee Token
# Check which token a validator uses for fees
cast call $FEE_MANAGER \
"validatorTokens(address)(address)" \
$ADMIN \
--rpc-url $RPCClaim Accumulated Fees (Distribute Fees)
# Anyone can call — transfers accumulated fees to validator
cast send $FEE_MANAGER \
"distributeFees(address,address)" \
$ADMIN \
$TUSD \
--private-key $PRIVATE_KEY \
--rpc-url $RPCView FeeManager Balance
# Check how much TUSD FeeManager holds (= total accumulated fees for all validators)
cast call $TUSD \
"balanceOf(address)(uint256)" \
$FEE_MANAGER \
--rpc-url $RPC10. Decode Data
Decode Function Selector (4 bytes)
cast 4byte 0xa6c07924
# Output: distributeFees(address,address)Decode Calldata
cast pretty-calldata 0xa6c079240000000000000000000000005266dfa5ae013674f8fdc832b7c601b838d94ee600000000000000000000000020c0000000000000000000000000000000000000Output
Possible methods:
- distributeFees(address,address)
------------
[000]: 0000000000000000000000005266dfa5ae013674f8fdc832b7c601b838d94ee6 (validator)
[020]: 00000000000000000000000020c0000000000000000000000000000000000000 (token)11. Example Scripts
Check All Tokens
#!/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 ""
doneCheck Validator Status
#!/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 ""
doneReferences
- Foundry Book — Cast
- ThaiChain TIP20 Specification — THAICHAIN-TIP21: Decimals is always 6
- ThaiChain Fee Manager Precompile