Dear Racers, have you ever wondered by what magic NFTs allow you to participate in the Stables ecosystem? Well, the answer is very simple: smart contracts! How do they work? Is it possible to consult the Stables smart contract? If so, what can we find interesting about it? We will explain everything to you in this article.
What is a smart contract?
First of all, let's start at the beginning. If you don't understand what a smart contract is, we will answer it right away.
A smart contract is defined as a decentralized computer program (it relies on a blockchain), automated (it executes itself when conditions are met) and transparent (anyone can access and consult it).
To put it simply, just imagine a traditional contract, but with a little touch of technological magic. In fact, when the conditions defined in advance are met, the contract is executed automatically, without the intervention of an intermediary. In short, trust is given to the code and no longer to human intervention.
Smart contracts are the quintessence of what is called decentralized finance. Without them, nothing you know could exist; especially our dear Stables project!
By the way, know that a smart contract is transparent and therefore can be consulted by anyone! Yes, you heard me correctly Racers, it is possible to read the Stables smart contract. Exciting, isn't it? Well, that's what we're going to discover together in the rest of this guide.
📎 To learn more about Stables, check out all of our blog posts!
Where to find the smart contract of Stables?
As you probably know, Stables is a fantasy game running on the Tezos blockchain. The choice of Tezos was made due to its high level of security, low energy consumption, and affordable transaction fees for users.
Like any blockchain, Tezos has explorers that allow you to track everything happening on it in real-time. There are several explorers available, with the most well-known being TzStats and TzKT. To begin, go to one of them (for the following steps, we'll use TzKT).
Next, you'll need to get your hands on the address(es) of the smart contract. These are easily accessible on the Stables blog, but we'll provide them here again:
Here are the addresses of the smart contracts:
- Stables Pass (NT NFT): KT1RqXzEKaChWrBpmfWUmUbMJ7zLRCW2F6YL
- Stables NFT Collection: KT1MQL8VjVQckk5A6uBfN9Qv2YUVJstG1CyH
- Stables Sale Contract: KT1JF9JfwRc9wwoMEQFUZDZBrVDvrazYdEFK
Select one of them and paste it into the search bar of the TzKT explorer. Like magic, you'll see a bunch of information displayed on your screen. Are you ready to decrypt them?
📎 Dive deeper by discovering what the Tezos blockchain and its token XTZ are all about!
How to read the Stables smart contract?
Visiting the Sale Contract
The TzKT tool provides us access to a whole bunch of information: the code itself, the latest operations performed by the contract, the different tokens it governs and their characteristics, as well as the metadata. These details will be the same, regardless of the contract you are observing.
To begin, let's take the third address from the list above. This corresponds to the contract responsible for the sale of NFTs. By pasting it into the search bar of the explorer, you can display all the mint operations of the users - including yours, Racer:
Here are the most recent operations executed by the smart contract. The latest one was performed on March 30, 2023, at 5:50 PM and corresponds to the most recent NFT minted by a community member.
As you can see, each movement includes two operations. The first one indicates that the user confirms their intention to mint an NFT on the Stables website, which triggers the "confirm_order" function within the smart contract.
Before we proceed, note that the information displayed is similar for all operations. At the top, you will find the transaction ID, the date, the block number in which it was executed, and whether it was approved or not. Below that, you have the person who invoked the smart contract and the beneficiary of the action. Finally, the amount of gas used for the operation is indicated. In fact, we can observe that the smart contract correctly executed the function, resulting in an expenditure of 0.012 XTZ in transaction fees.
Next, we can see that the "mint" function of the smart contract is called automatically, which will result in transferring the NFT from the Stables team's wallet address to the wallet address of the user who performed the operation.
Moreover, as you may also notice, the NFT has been transferred from the sale contract (KTAJF9Jf...) to the collection contract (KT1MQL8V...). Speaking of this contract, let's take a tour!
Visiting the Collection Contract
Just like before, copy and paste the address of this contract into the search bar of the TzKT website. In case you need it again, here it is: KT1MQL8VjVQckk5A6uBfN9Qv2YUVJstG1CyH.
In the "CODE" tab, you can once again observe the code that governs the smart contract of the collection. In the "TOKENS" tab, you can display the list of the 6,666 NFTs in the collection. On the right side of your screen, you will find the details of each of them, including the token ID and the attributes of the associated artwork.
Let's go to the "OPERATIONS" tab. As the name suggests, it allows you to observe the latest operations performed on this smart contract. Let's focus on the most recent transactions, as of the time of writing this article. You'll see, it tells us a very simple story!
On the right side of your screen, here's what is displayed for the first operation:
This transaction informs us that a user, whose address is displayed on the screen, authorized the Objkt marketplace to interact with their token named "IZARDO DU RIB" at 7:32 in the morning on July 5th. What should we take away from this? A user has listed their NFT for sale on the marketplace.
The second transaction takes place at 8:41 in the morning. Here it is:
It is the Objkt marketplace that invoked the smart contract through the "transfer" function. In other words, it informs the contract of a user's request to obtain the token, based on the conditions predefined by the seller. As you may have guessed, a user interacted with the Objkt marketplace to purchase the mentioned NFT.
Finally, here is the last operation, performed at 8:41 as well:
As indicated in the Tezos explorer, the smart contract calls the "do_transfer" function, which it executes immediately. As a result, the token "IZARDO DU RIB" is transferred from the holder's address to the one who interacted with the Objkt marketplace. This is the final step, and the buyer receives their NFT, which leaves the wallet of its previous owner.
There you have it! We have read together what happens on the Stables smart contract. In just a few minutes, you were able to discover what occurs when a user lists their NFT for sale, and another user decides to acquire it!
📎 To go further: Does having a good horse in real life matter in Stables?
An Easter Egg in the Stables Smart Contract?
There are many interesting things to take away from the Stables smart contract. However, it would require some coding knowledge to fully grasp them. Nevertheless, we can show you something interesting that should pique your curiosity, dear Racers! It's a sort of Easter egg, a hidden function in the program.
To understand this, you should know that Stables' metadata is not stored on the blockchain but on servers owned by the project. This is a common choice for many NFT projects, as storing metadata on the blockchain would result in very high gas fees. However, Stables offers a way to verify that none of the metadata has been changed after minting.
The token ID is calculated in a unique way. First, the following information is concatenated: the NFT number in the collection, the horse's country of birth, the country code, the year of birth, the complete date of birth, and finally, the official name of the horse. This results in something like "1:FR:2023:2023-01-01:NAME". Then, the following transformation is applied:
- bytes: 31 3a 46 52 3a 32 30 32 33 3a 32 30 32 33 2d 30 31 2d 30 31 3a 44 41 56 49 44
- little: 109732130401448801075897904080883403357190557740499221633972785
- modulo 10^12: 221633972785
- And there you have it, you get the ID of your token. Using this system, you can constantly verify that Stables does not modify the intrinsic data of your NFT, especially the horse associated with it!
📎 Discover how to buy Stables NFTs with your XTZ.
Conclusion
There you have it, we have reached the end of our journey into the Stables smart contract. Of course, we didn't go into all the details, as it would have required much more time.
Through this article, we were able to demystify the concept of smart contracts and understand what lies behind a simple NFT purchase operation in the Stables collection.
We hope this article has given you an enlightened insight into how to read the smart contracts of the collection and that you enjoyed the hidden Easter egg! If you want to continue learning or if you have any questions, feel free to do so on our Discord server!
📎 The inaugural race of Stables is just around the corner, don't miss it!
Related posts
Discover our other articles
Ambassadors, your VIP experience is around the corner
Everything your need to know about the inaugural race
MetaMask Snaps: It is now possible to use Tezos on MetaMask wallets!
Don't miss any news from Stables anymore
Want to find out more about the world of Stables? You've come to the right place.