Skip to content

romanovichim/TONQuest1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TON Speedrun

🚩 Challenge 1: Simple NFT Deploy

🎫 Mint simple NFT on TON . Let's look at smart contracts of the NFT standard in TON. Get information about the deployed collection in the TON network. And send a message to the collection and thus deploy the NFT

🌟 The final deliverable will be NFT minted on the TON testnet.

💬 Meet other builders working in TON and get help in the official dev chat or TON learn tg


Checkpoint 0: 📦 Install 📚

Required:

(⚠️ Don't install the linux package yarn make sure you install yarn with npm i -g yarn or even sudo npm i -g yarn!)

git clone https://github.com/romanovichim/TONQuest1.git
cd challenge-1
yarn install

Checkpoint 1: 🎓 NFT Standart in TON ✒️

So, 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.

In the TON network, the NFT standard describes two types of contracts:

  • collection smart contract
  • smart contract for a separate NFT(NFT Item)

Collection smart contract allows you to mint NFT.

I think that's enough theory, let's look at the code!


Checkpoint 2: 👓 Let's look at the contracts 💫

Open the contracts folder:

1

Smart contracts in TON are usually written in FunC or Tact. In the folder, you can see the collection NFT smart contract and the NFT element smart contract written in the FunC language. The imports folder contains the helper code.

In the next quests, we will learn how to deploy smart contracts, but in this case, I decided to help you and have already deposited the smart contract of the collection. By the way, you can see its code in the nft-collection.fc file.

Smart contracts in TON communicate by messages, so usually smart contracts consist of message handlers and get methods.

Get methods - methods that can return some information, for example, about the NFT collection. Let's make a request to the collection and get information about the collection where we will mint our NFT.


Checkpoint 3: 📐 Let's get information about the collection 📏

Ready to make a request to the testnet?!?

For a request in scripts folder in getCollectionData.ts file, I prepared the getCollectionData() function, which will execute a request to the get_collection_data get method:

image

Let's run it with the command yarn getcol:

yarn getcol

Result:

image

get_collection_data mandatory NFT standard method, this method returns:

next_item_index - the count of currently deployed NFT items in collection. collection_content - collection content in a format that complies with standard TEP-64. owner_address - collection owner address, zero address if no owner.

next_item_index is needed to understand what number we should release NFT with, i.e. what is the next number)


Checkpoint 4: 💊 Сollect the body of the message for NFT mint 💾

As mentioned above, smart contracts exchange messages, in order to mint the NFT, you need to send a message to the collection contract. You can put some paylod in the message - message body. Let's assemble the body for mint NFT. Open deployNft.ts file. It looks like this:

image

The body of the message will be a cell - the data type of the TON network. The first thing we will put in the message will be the service parameters op and query_id, we will not dwell on them in this quest.

Next is the index of our future NFT, a small number of coins and a cell with an address and, in fact, what will be stored inside the NFT. Since this is an example, we will simply use the item.json as a NFT item content.

P.S Assembly of the body is in the file deployNFT.ts


Checkpoint 5: 💸 Testnet Coins 💰

An attentive reader may have a question, who should send a message with the body we have collected to the smart contract of the collection. There are wallets for this, the wallet can receive external messages and send internal ones, so for mint nft we need a wallet. There are many different wallets in TON, but I suggest you use a Tonkeeper.

Let's use the wallet by switching it to the test network and get coins in the test network - we need them to send a message:

  1. Go to the settings and scroll to the very bottom until the inscription "Tonkeeper version X"
  2. Click 6 times in a row quickly on the Tonkeeper icon above the inscription - the menu for developers will open
  3. select switch to the test network in it
  4. to get to the wallet in the test network, test TON, you need to use the tap: https://t.me/testgiver_ton_bot

Checkpoint 6: 📌 Mint NFT 📌

Ready to mint to the testnet?!?

yarn deploynft 

On the screen you will see a QR code, scan it and confirm the transaction in the wallet.

Congratulations, you minted nft on the network TON!

Mainnet

If you want to mint your NFT on mainnet (for example, so that it is displayed in the society.ton.org profile). Follow these steps:

  1. Open scripts/utils.ts file and delete testnet. part from toncenter endpoint url. After that it should look like this:
export const toncenter = new TonClient({
	endpoint: 'https://toncenter.com/api/v2/jsonRPC',
});
  1. Use your mainnet wallet to scan this qr-code.

P.S. and don't forget to change the address in script/deployNFT.ts to your address =)


Checkpoint 7: 🎫 Check NFT 😀

Let's check if you did everything right. Let's find your NFT in the blockchain explorer.

Testnet

Take the address of our collection and open it in the explorer:

https://testnet.explorer.tonnft.tools/collection/EQDf6HCOggN_ZGL6YsYleN6mDiclQ_NJOMY-x8G5cTRDOBW4

Mainnet

For Mainnet, use you can use this link:

https://explorer.tonnft.tools/collection/EQDf6HCOggN_ZGL6YsYleN6mDiclQ_NJOMY-x8G5cTRDOBW4

Check the NFT

Scroll down and find your NFT in the list!

Since this is an example, the link in the content of NFT is not working, but when you create your projects, you can sew up any links you want.

P.S. If you want to see an NFT in your wallet, don't forget to change owner address in deployNft.ts file!


⚔️ Side Quests

Quick results are great, but to play longer, enjoy the ecosystem, I suggest you the following tutorials:

  • Understand how to compile a smart contract
  • Learn to write tests for smart contracts
  • And of course, deploy your smart contract to the test network

After that, I suggest you delve into the language for TON smart contracts: