Web3: TON Development Survival Guide
4/29/24About 1 min
Web3: TON Development Survival Guide 💎
So you want to build on TON (The Open Network)? Welcome to the land of Sharding and Asynchrony. Forget everything you know about EVM; we're not in Kansas anymore.
The Core Weirdness
- Not Your Grandpa's EVM: Because TON is asynchronous, the TVM (TON Virtual Machine) is totally incompatible with the Ethereum Virtual Machine (EVM). Don't try to copy-paste your Solidity code; it won't work.
- Address Magic: A contract's address isn't just random; it's calculated from its deployed bytecode AND its initial data. Change a variable, change the address.
Pick Your Weapon (Languages)
- Tact: The "Easy Mode". It's simple, readable, and compiles down to FunC. Great for keeping your sanity.
- FunC: The "C-like" standard. Officially supported and robust. If you like semicolons and low-level control, this is for you.
- Fift: The "Assembly" of TON. Unless you enjoy pain or are writing a compiler, stay away.
⚠️ "Gotchas" (Read Before You Cry)
- Sharding Headache: Data is scattered across shards. You don't get a global state view for free; often, you have to manually aggregate data from different places. Fun, right?
- Async Chaos: Asynchronous calls mean Race Conditions are your new best friend. Manage your state carefully, or things will get weird.
- Wallet = Contract: There are no "EOA" (Externally Owned Accounts) like in Ethereum. Your wallet IS a contract. One public key can control multiple wallet instances.
- The Gas Situation:
- No Refunds: If your contract crashes, say goodbye to your Gas. No automatic refunds.
- Manual Returns: You often have to write code to manually send back unused Gas at the end of a transaction chain.
- Failed? Still Pay: Even failed transactions burn Gas.
- The Cap: A single contract execution is capped at 1 TON of Gas. Don't go crazy.
- Rent is Due: Contracts have to pay storage rent. If they run out of money, they might get frozen or deleted.
- Upgradable: Yes, you can upgrade contract code.
- Precision: Standard token precision is 9 decimals, not 18.
Show Me The Code
Check out this example for a Jetton (Token) Contract:
https://github.com/TonoxDeFi/capped-fungible-token/tree/main