Create Token
Deploy a new CW20 token on XYZ Chain with the xyz token create command.
Setup
Before creating tokens, ensure the CW20 base contract is deployed.
Deploy CW20 Base Contract
# Run the deployment script
./scripts/deploy-cw20.sh
Downloading CW20 base contract v2.0.0...
Deploying to xyz-testnet-1...
Transaction hash: ABC123...
Code ID: 1
Success! Configure xyz CLI:
xyz config set cw20-code-id 1
xyz config set cw20-code-id 1
Verify:
xyz config get cw20-code-id
# 1
Create a Token
xyz token create \
--name "My Token" \
--symbol "MTK" \
--decimals 6 \
--initial-supply 1000000000000 \
--from mykey
Required Flags
| Flag | Description | Example |
|---|
--name | Token name | ”My Token” |
--symbol | Trading symbol (3-12 chars) | “MTK” |
--decimals | Decimal places (0-18) | 6 |
--from | Signing key | mykey |
Optional Flags
| Flag | Description | Default |
|---|
--initial-supply | Starting supply | 0 |
--minter | Minter address | Creator |
--cap | Maximum supply | Unlimited |
--dry-run | Simulate only | false |
Examples
Basic Token
xyz token create \
--name "My Token" \
--symbol "MTK" \
--decimals 6 \
--from mykey
Creates a token with no initial supply. You’ll need to mint tokens afterward.
Token with Initial Supply
xyz token create \
--name "Reward Token" \
--symbol "RWRD" \
--decimals 6 \
--initial-supply 1000000000000 \
--from mykey
Creates 1,000,000 tokens (with 6 decimals) sent to the creator.
Fixed Supply Token
xyz token create \
--name "Fixed Token" \
--symbol "FIX" \
--decimals 6 \
--initial-supply 1000000000000 \
--cap 1000000000000 \
--from mykey
Creates a token with fixed 1M supply (cap equals initial supply).
Token with Different Minter
xyz token create \
--name "DAO Token" \
--symbol "DAO" \
--decimals 6 \
--minter xyz1daocontract... \
--from mykey
Sets a DAO contract as the minter instead of the creator.
Dry Run
Simulate token creation without broadcasting:
xyz token create \
--name "Test Token" \
--symbol "TEST" \
--decimals 6 \
--from mykey \
--dry-run
Output:
Dry run mode - transaction not broadcast
Estimated gas: 250,000
Estimated fee: 2,500 uxyz
Token Details:
Name: Test Token
Symbol: TEST
Decimals: 6
Initial Supply: 0
Minter: xyz1youraddress...
Output
Successful creation returns:
Token Created Successfully!
Contract: xyz1tokencontract123...
Name: My Token
Symbol: MTK
Decimals: 6
TxHash: ABC123DEF456...
Gas Used: 234567
Block: 12345
Save the contract address! You’ll need it for all future operations (mint, transfer, etc.).
Track Your Token
Add the token to your configuration for balance queries:
# Add to tracked tokens
xyz config set cw20-tokens xyz1tokencontract123...
# Now balance queries include this token
xyz balance --all --key mykey
Decimals Guide
The decimals field determines the smallest unit:
| Decimals | 1 Token = | Use Case |
|---|
| 0 | 1 | NFT-like, indivisible |
| 6 | 1,000,000 | Standard (like uxyz) |
| 8 | 100,000,000 | Bitcoin-style |
| 18 | 10^18 | Ethereum-style |
Use 6 decimals to match the native uxyz denomination.
Error Handling
The CLI provides user-friendly error messages:
| Error | Meaning | Solution |
|---|
| ”cw20-code-id not configured” | Missing code ID | Run xyz config set cw20-code-id 1 |
| ”insufficient funds” | Not enough uxyz | Fund your account |
| ”invalid symbol” | Symbol too long/short | Use 3-12 characters |
Under the Hood
xyz token create executes a MsgInstantiateContract:
{
"code_id": 1,
"label": "MTK Token",
"msg": {
"name": "My Token",
"symbol": "MTK",
"decimals": 6,
"initial_balances": [
{
"address": "xyz1creator...",
"amount": "1000000000000"
}
],
"mint": {
"minter": "xyz1creator...",
"cap": null
}
},
"funds": []
}
Next Steps