Fungible Tokens (Jettons)
This page lists common examples of working with Fungible Tokens (Jettons).
Jettons are token standards on the TON Blockchain, designed to create fungible tokens (similar to ERC-20 on Ethereum) with a decentralized approach. They are implemented as a pair of smart contracts, typically consisting of two core components:
- Jetton Master Contract (Jetton master)
- Jetton Wallet Contract (Jetton wallet)
These contracts interact with each other to manage token supply, distribution, transfers, and other operations related to the Jetton.
Jetton Master Contract
The Jetton Master Contract serves as the central entity for a given Jetton. It maintains critical information about the Jetton itself. Key responsibilities and data stored in the Jetton Master Contract include:
-
Jetton metadata: Information such as the token’s name, symbol, total supply, and decimals.
-
Minting and Burning: When new Jettons are minted (created), the Jetton Master manages the creation process and distributes them to the appropriate wallets. It also manages the burning (destruction) of tokens as needed.
-
Supply Management: The Jetton Master keeps track of the total supply of Jettons and ensures proper accounting of all issued Jettons.
Jetton Wallet Contract
The Jetton Wallet Contract represents an individual holder’s token wallet and is responsible for managing the balance and token-related operations for a specific user. Each user or entity holding Jettons will have its own unique Jetton Wallet Contract. Key features of the Jetton Wallet Contract include:
-
Balance tracking: The wallet contract stores the user’s token balance.
-
Token Transfers: The wallet is responsible for handling token transfers between users. When a user sends Jettons, the Jetton Wallet Contract ensures proper transfer and communication with the recipient’s wallet. The Jetton Master is not involved in this activity and does not create a bottleneck. Wallets can use TON’s sharding capability in a great way
-
Token burning: The Jetton Wallet interacts with the Jetton Master to burn tokens.
-
Owner control: The wallet contract is owned and controlled by a specific user, meaning that only the owner of the wallet can initiate transfers or other token operations.
Examples
Common examples of working with Jettons.
Accepting Jetton transfer
Transfer notification message have the following structure.
▶️ Open in Web IDEUse receiver function to accept token notification message.
The sender of a transfer notification must be validated because malicious actors could attempt to spoof notifications from an unauthorized account. If this validation is not done, the contract may accept unauthorized transactions, leading to potential security vulnerabilities.
Validation is done using the Jetton address from the contract:
- Sender sends message with
0xf8a7ea5
as its 32-bit header (opcode) to his Jetton wallet. - Jetton wallet transfers funds to contract’s Jetton wallet.
- After successful transfer accept, contract’s Jetton wallet sends transfer notification to his owner contract.
- Contract validates the Jetton message.
You may obtain contract’s Jetton wallet is done using the contractAddress()
function or calculate this address offchain.
To obtain the Jetton wallet’s state init, you need the wallet’s data and code. While there is a common structure for the initial data layout, it may differ in some cases, such as with USDT.
Since notifications originate from your contract’s Jetton wallet, the function myAddress()
should be used in ownerAddress
field.
Sending Jetton transfer
A Jetton transfer is the process of sending a specified amount of Jettons from one wallet (contract) to another.
To send Jetton transfer use send()
function.
Burning Jetton
Jetton burning is the process of permanently removing a specified amount of Jettons from circulation, with no possibility of recovery.
▶️ Open in Web IDEUSDT Jetton operations
Operations with USDT (on TON) remain the same, except that the JettonWalletData
will have the following structure: