Simple Token Balance
Before starting any project, it’s crucial to establish a solid foundation. A key step is compiling a comprehensive list of requirements before moving to implementation. For a token project, two critical elements need attention from the outset:
Name and Ticker: Choose a unique and compelling name and ticker symbol. For this project, we’ve selected “MyFirstToken” (MFT). Ensuring uniqueness is vital to avoid duplication.
Token Supply: Decide if the token will have a fixed supply. To keep things simple, we’ll use a fixed supply.
Additionally, we must track:
Token Circulation: Monitor the number of tokens in circulation versus those still in the initial supply.
Ownership: The token owner, responsible for deployment costs, holds initial ownership.
Now, let’s review the structure of our token class, which will lay the groundwork for developing the project.
Before diving into token operations, our first step is to focus on the constructor code. Here, we typically execute the Token Generation Event (TGE), transferring all initial tokens to the rightful owner. This can be easily accomplished using the CRC_Wallet class, as we’ve recently explored.
Next, we’ll define the key calls needed to query the contract and extract information using Special Native Calls (SNCs). The most commonly used include:
__GetTotalSupply: Retrieves the total token supply.
__GetCirculatingSupply: Provides the number of tokens sold so far.
__GetTokenName: Returns the token’s name.
__GetTokenTicker: Retrieves the token’s ticker symbol.
With this understanding, let’s implement these functions, which should take no more than 10 minutes.
These calls don’t modify the smart contract’s state and are executed by a single node without requiring a transaction. We can quickly test them using the debugging tool to view the contract’s output. Let’s set up a testing section for our initial methods and review the results.
If everything is executed correctly, the output should resemble the following example:
<Image>
Last updated