You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here and following we use "Jetton" with capital J as designation for entirety of tokens of the same type, while "jetton" with j as designation of amount of tokens of some type.
Jettons are organized as follows: each Jetton has master smart-contract which is used to mint new jettons, account for circulating supply and provide common information.
At the same time information about amount of jettons owned by each user is stores in decentralized manner in individual (for each owner) smart-contracts called "jetton-wallets".
Example: if you release a Jetton with circulating supply of 200 jetton which are owned by 3 people, then you will deploy 4 contracts: 1 Jetton-master and 3 jetton-wallets.
amount - amount of transferred jettons in elementary units.
destination - address of the new owner of the jettons.
response_destination - address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.
custom_payload - optional custom data (which is used by either sender or receiver jetton wallet for inner logic).
forward_ton_amount - the amount of nanotons to be sent to the destination address.
forward_payload - optional custom data that should be sent to the destination address.
Should be rejected if:
message is not from the owner.
there is no enough jettons on the sender wallet
there is no enough TON (with respect to jetton own storage fee guidelines and operation costs) to process operation, deploy receiver's jetton-wallet and send forward_ton_amount.
After processing the request, the receiver's jetton-wallet must send at least in_msg_value - forward_ton_amount - 2 * max_tx_gas_price - 2 * fwd_fee to the response_destination address.
If the sender jetton-wallet cannot guarantee this, it must immediately stop executing the request and throw error. max_tx_gas_price is the price in Toncoins of maximum transaction gas limit of FT habitat workchain. For the basechain it can be obtained from ConfigParam 21 from gas_limit field. fwd_fee is forward fee for transfer request, it can be obtained from parsing transfer request message.
Otherwise should do:
decrease jetton amount on sender wallet by amount and send message which increase jetton amount on receiver wallet (and optionally deploy it).
if forward_amount > 0 ensure that receiver's jetton-wallet send message to destination address with forward_amount nanotons attached and with the following layout:
TL-B schema:
sender is address of the previous owner of transferred jettons.
forward_payload should be equal with request's forward_payload.
If forward_amount is equal to zero, notification message should not be sent.
Receiver's wallet should send all excesses of incoming message coins to response_destination with the following layout:
TL-B schema: excesses#d53276db query_id:uint64 = InternalMsgBody; query_id should be equal with request's query_id.
forward_payload format
If you want to send a simple comment in the forward_payload then the forward_payload must starts with 0x00000000 (32-bits unsigned integer equals to zero) and the comment is contained in the remainder of the forward_payload.
If comment does not begin with the byte 0xff, the comment is a text one; it can be displayed "as is" to the end user of a wallet (after filtering invalid and control characters and checking that it is a valid UTF-8 string).
For instance, users may indicate the purpose ("for coffee") of a simple transfer from their wallet to the wallet of another user in this text field.
On the other hand, if the comment begins with the byte 0xff, the remainder is a "binary comment", which should not be displayed to the end user as text (only as hex dump if necessary).
The intended use of "binary comments" is, e.g., to contain a purchase identifier for payments in a store, to be automatically generated and processed by the store's software.
If the forward_payload contains a binary message for interacting with the destination smart contract (for example, with DEX), then there are no prefixes.
response_destination - address where to send a response with confirmation of a successful burn and the rest of the incoming message coins.
custom_payload - optional custom data.
Should be rejected if:
message is not from the owner.
there is no enough jettons on the sender wallet
There is no enough TONs to send after processing the request at least in_msg_value - max_tx_gas_price to the response_destination address.
If the sender jetton-wallet cannot guarantee this, it must immediately stop executing the request and throw error.
Otherwise should do:
decrease jetton amount on burner wallet by amount and send notification to jetton master with information about burn.
Jetton master should send all excesses of incoming message coins to response_destination with the following layout:
TL-B schema: excesses#d53276db query_id:uint64 = InternalMsgBody; query_id should be equal with request's query_id.
Get-methods
get_wallet_data() returns (int balance, slice owner, slice jetton, cell jetton_wallet_code) balance - (uint256) amount of jettons on wallet. owner - (MsgAddress) address of wallet owner; jetton - (MsgAddress) address of Jetton master-address; jetton_wallet_code - (cell) with code of this wallet;
Jetton master contract
Get-methods
get_jetton_data() returns (int total_supply, int mintable, slice admin_address, cell jetton_content, cell jetton_wallet_code) total_supply - (integer) - the total number of issues jettons mintable - (-1/0) - flag which indicates whether number of jettons can increase admin_address - (MsgAddressInt) - address of smart-contrac which control Jetton jetton_content - cell - data in accordance to Token Data Standard #64 jetton_wallet_code - cell - code of wallet for that jetton
get_wallet_address(slice owner_address) return slice jetton_wallet_address
Returns jetton wallet address (MsgAddressInt) for this owner address (MsgAddressInt).
Summary
A standard interface for Jettons (TON fungible tokens).
Motivation
A standard interface will greatly simplify interaction and display of different tokenized assets.
Jetton standard describes:
Guide
Useful links
Specification
Here and following we use "Jetton" with capital
J
as designation for entirety of tokens of the same type, while "jetton" withj
as designation of amount of tokens of some type.Jettons are organized as follows: each Jetton has master smart-contract which is used to mint new jettons, account for circulating supply and provide common information.
At the same time information about amount of jettons owned by each user is stores in decentralized manner in individual (for each owner) smart-contracts called "jetton-wallets".
Example: if you release a Jetton with circulating supply of 200 jetton which are owned by 3 people, then you will deploy 4 contracts: 1 Jetton-master and 3 jetton-wallets.
Jetton wallet smart contract
Must implement:
Internal message handlers
1.
transfer
Request
TL-B schema of inbound message:
query_id
- arbitrary request number.amount
- amount of transferred jettons in elementary units.destination
- address of the new owner of the jettons.response_destination
- address where to send a response with confirmation of a successful transfer and the rest of the incoming message Toncoins.custom_payload
- optional custom data (which is used by either sender or receiver jetton wallet for inner logic).forward_ton_amount
- the amount of nanotons to be sent to the destination address.forward_payload
- optional custom data that should be sent to the destination address.Should be rejected if:
forward_ton_amount
.in_msg_value - forward_ton_amount - 2 * max_tx_gas_price - 2 * fwd_fee
to theresponse_destination
address.If the sender jetton-wallet cannot guarantee this, it must immediately stop executing the request and throw error.
max_tx_gas_price
is the price in Toncoins of maximum transaction gas limit of FT habitat workchain. For the basechain it can be obtained fromConfigParam 21
fromgas_limit
field.fwd_fee
is forward fee for transfer request, it can be obtained from parsing transfer request message.Otherwise should do:
amount
and send message which increase jetton amount on receiver wallet (and optionally deploy it).forward_amount > 0
ensure that receiver's jetton-wallet send message todestination
address withforward_amount
nanotons attached and with the following layout:TL-B schema:
query_id
should be equal with request'squery_id
.amount
amount of transferred jettons.sender
is address of the previous owner of transferred jettons.forward_payload
should be equal with request'sforward_payload
.If
forward_amount
is equal to zero, notification message should not be sent.response_destination
with the following layout:TL-B schema:
excesses#d53276db query_id:uint64 = InternalMsgBody;
query_id
should be equal with request'squery_id
.forward_payload
formatIf you want to send a simple comment in the
forward_payload
then theforward_payload
must starts with0x00000000
(32-bits unsigned integer equals to zero) and the comment is contained in the remainder of theforward_payload
.If comment does not begin with the byte
0xff
, the comment is a text one; it can be displayed "as is" to the end user of a wallet (after filtering invalid and control characters and checking that it is a valid UTF-8 string).For instance, users may indicate the purpose ("for coffee") of a simple transfer from their wallet to the wallet of another user in this text field.
On the other hand, if the comment begins with the byte
0xff
, the remainder is a "binary comment", which should not be displayed to the end user as text (only as hex dump if necessary).The intended use of "binary comments" is, e.g., to contain a purchase identifier for payments in a store, to be automatically generated and processed by the store's software.
If the
forward_payload
contains a binary message for interacting with the destination smart contract (for example, with DEX), then there are no prefixes.These rules are the same with the payload format when simply sending Toncoins from a regular wallet (Smart Contract Guidelines: Internal Messages, 3).
2.
burn
Request
TL-B schema of inbound message:
query_id
- arbitrary request number.amount
- amount of burned jettonsresponse_destination
- address where to send a response with confirmation of a successful burn and the rest of the incoming message coins.custom_payload
- optional custom data.Should be rejected if:
in_msg_value - max_tx_gas_price
to theresponse_destination
address.If the sender jetton-wallet cannot guarantee this, it must immediately stop executing the request and throw error.
Otherwise should do:
amount
and send notification to jetton master with information about burn.response_destination
with the following layout:TL-B schema:
excesses#d53276db query_id:uint64 = InternalMsgBody;
query_id
should be equal with request'squery_id
.Get-methods
get_wallet_data()
returns(int balance, slice owner, slice jetton, cell jetton_wallet_code)
balance
- (uint256) amount of jettons on wallet.owner
- (MsgAddress) address of wallet owner;jetton
- (MsgAddress) address of Jetton master-address;jetton_wallet_code
- (cell) with code of this wallet;Jetton master contract
Get-methods
get_jetton_data()
returns(int total_supply, int mintable, slice admin_address, cell jetton_content, cell jetton_wallet_code)
total_supply
- (integer) - the total number of issues jettonsmintable
- (-1/0) - flag which indicates whether number of jettons can increaseadmin_address
- (MsgAddressInt) - address of smart-contrac which control Jettonjetton_content
- cell - data in accordance to Token Data Standard #64jetton_wallet_code
- cell - code of wallet for that jettonget_wallet_address(slice owner_address)
returnslice jetton_wallet_address
Returns jetton wallet address (MsgAddressInt) for this owner address (MsgAddressInt).
TL-B schema
crc32('transfer query_id:uint64 amount:VarUInteger 16 destination:MsgAddress response_destination:MsgAddress custom_payload:Maybe ^Cell forward_ton_amount:VarUInteger 16 forward_payload:Either Cell ^Cell = InternalMsgBody') = 0x8f8a7ea5 & 0x7fffffff = 0xf8a7ea5
crc32('transfer_notification query_id:uint64 amount:VarUInteger 16 sender:MsgAddress forward_payload:Either Cell ^Cell = InternalMsgBody') = 0xf362d09c & 0x7fffffff = 0x7362d09c
crc32('excesses query_id:uint64 = InternalMsgBody') = 0x553276db | 0x80000000 = 0xd53276db
crc32('burn query_id:uint64 amount:VarUInteger 16 response_destination:MsgAddress custom_payload:Maybe ^Cell = InternalMsgBody') = 0x595f07bc & 0x7fffffff = 0x595f07bc
crc32('internal_transfer query_id:uint64 amount:VarUInteger 16 from:MsgAddress response_address:MsgAddress forward_ton_amount:VarUInteger 16 forward_payload:Either Cell ^Cell = InternalMsgBody') = 0x978d4519 & 0x7fffffff = 0x178d4519
crc32('burn_notification query_id:uint64 amount:VarUInteger 16 sender:MsgAddress response_destination:MsgAddress = InternalMsgBody') = 0x7bdd97de & 0x7fffffff = 0x7bdd97de
Drawbacks
There is no way to get actual wallet balance onchain, because when the message with balance will arrive, wallet balance may be not actual.
Rationale and alternatives
Distributed architecture "One wallet - one contract" well described in the NFT standard in paragraph "Rationale".
Prior art
Unresolved questions
Future possibilities
There was an idea to implement external message tokens (by EmelyanenkoK).
Changelog
31 Aug 2022 - Added
forward_payload
format.The text was updated successfully, but these errors were encountered: