FunC Journey: Part 3

Article image

This is the third part of the FunC journey, in which we will look at what tokens are, why standards are needed and what are the standards for tokens in TON, we will analyze how the Jetton standard and the NFT collection standard work at the top level, and also we will analyze some non-obvious points in the implementation examples of Jetton and NFT standards.

Article image

The journey continues, in search of new opportunities, you stumble upon a building, a shrine of knowledge... . Anticipating a lot of questions, the guardian shrine of knowledge sends you to the Tokens section.


Article image

Crypto tokens are units of account for some digital asset in some network. It is important to note that a token does not usually mean a cryptocurrency, but a record distributed on the blockchain, which is managed using smart contracts. The smart contract contains the values of the balances on the accounts of token holders, and the smart contract also provides the ability to transfer tokens from one account to another.

And everything seems to be simple, we are making a smart contract that can store balances and transfer tokens in some way. But if everyone invents a wheel, then it will be difficult for applications like wallets, games, analytical platforms to interact with your smart contracts.

Therefore, there are standards in blockchain networks that are being developed together with the community.

The thought of creating your own tokens so that future travelers on the TON can use them leads you to the guardian again, you ask the question: Where can I see the standards?

TEP and Standarts

Article image

Blockchains usually have separate pages on github or on a platform with the necessary mechanics, where you can make proposals on standards.

In TON, this is a github repository.

Importantly, these pages are not a forum or a place for free discussion of the blockchain, so be responsible for your posts if you want to offer something in this repository.

The first standard we'll look at is the token metadata standard. For applications like wallets or marketplaces it is quite useful to be able automatically retrieve information for display. Token data standard allows to simplify this process and uniform the way of token display across different applications.


Since tokens are smart contracts, there may be errors or backdoors in them. Therefore, it is worth studying smart contracts before using them.

You have been traveling on web3 for more than a day and you understand that you have already heard about tokens on other continents, but there are clearly differences in TON...

Difference of tokens in TON

The architecture of smart contracts of tokens in TON differs from the architecture of smart contracts in other networks, since the TON is asynchronous, the interaction takes place according to the actor model and scaling in TON is based on the concept of sharding.

The key difference from the standards of other networks is the lack of one smart contract that does all the work. For example, if you want to release a NFT collection (we will talk about NFT in more detail later), then each element will be a separate smart contract, and there will also be a separate smart contract for the entire collection.

Example from Standart: if you release a collection that contains 10 000 items, then you will deploy 10 001 smart contracts.

You may have a question - why such an implementation was chosen? Briefly:

  • Such a scheme makes it possible to make gas consumption predictable
  • Such a scheme does not scale

Full explanation is in the NFT standard .

Types of tokens

One of the possible classifications of tokens is the classification by fungibility.

Fungible tokens are assets that are not unique and can be easily exchanged for another asset of the same type. Such tokens are made in such a way that each token is equivalent to the next token.

The standard for a fungible token in TON is Jetton.

Non-fungible tokens are assets, each instance of which is unique (specific) and cannot be replaced by another similar asset. A non-fungible token is some kind of digital entity certificate with the ability to transfer the certificate through some mechanism.

The standard for a fungible token in TON is NFT Standart.


Article image

So, the standard for a fungible token is Jetton.

The Jetton standard token should consist of two types of smart contracts:

  • master contract
  • contract wallet

Each Jetton has a main smart contract (let's call it a master contract) that is used to mint new Jettons, account for the total supply, and provide general information about the token.

Information about the number of tokens owned by each user is stored in smart contracts called the Jetton wallet.

There is a good example in the standard documentation:

If you release Jetton with a supply of 200 Jettons owned by 3 people, then you need to deploy 4 contracts: 1 Jetton master and 3 jetton wallets.

In order to make it easier for you to understand the standard, I made a lesson that not only understands the standard, but also understands an example of the implementation of the master contract and Jetton wallets.


Article image

The NFT, of course, also has its own standard. As mentioned above in TON, each NFT Item and NFT Collection are separate smart contracts.

NFTs look like a great opportunity to capture FunC your journey, but a couple of questions remain:

  • how to get a full link to the content if there is no single list in the smart contract
  • how to get the address of the NFT or Token smart contract and what kind of StateInit that allows you to do this

StateInit trick

Consider the process of deploying a smart contract to the network. The code and data for the new smart contract are combined into a StateInit structure, the address of the new smart contract (equal to the hash of this StateInit structure) is calculated and output, and then an external message is created with the address destination equal to the address of the new smart contract. This message contains both the correct StateInit for the new smart contract and a non-trivial payload (signed with the correct private key).

For us, this means that we can get the address of the smart contract of the token from the address to which we need to send the tokens. In simple terms, using the address and wallet code, we will collect the StateInit of the wallet and from it we will get the address of the token wallet we need.

This is possible, since hashing functions are deterministic, which means that for different input data there will be a different hash, while for the same input data the hash function will always return a uniform hash.

NFT item content

Let's say we want to get the address of the collection element, its content, let's say a link to the picture. And everything seems to be simple, we pull the Get-method and get the information. BUT in accordance with the NFT standard in TON, in this way we will not get a complete link, but only a part, the so-called individual element content.

To get the full content, you need:

  • by the get-method of the element get_nft_data(), we get the element index and individual content, as well as the initialization sign
  • check if the element is initialized (More about this in lesson 10, where the NFT standard is discussed)
  • if the element is initialized, then by the get-method of the collection get_nft_content(int index, cell individual_content), we will get the full content (full address) for a separate element

In order to make it easier for you to understand the standard, I made a lesson


On this series of articles, the journey through FunC ends. I publish new lessons in my channel, I think they can help you if you plan to start developing on TON.

Other parts:

Related Posts