# 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:

<mark style="color:green;">**Name and Ticker:**</mark> Choose a unique and compelling name and ticker symbol. For this project, we’ve selected “MyFirstToken” (MFT). Ensuring uniqueness is vital to avoid duplication.

<mark style="color:green;">**Token Supply:**</mark> Decide if the token will have a fixed supply. To keep things simple, we’ll use a fixed supply.

\
Additionally, we must track:

<mark style="color:green;">**Token Circulation:**</mark> Monitor the number of tokens in circulation versus those still in the initial supply.

<mark style="color:green;">**Ownership:**</mark> 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.

```javascript
var CRC_Contract = {

                    _TotalSupply : 100000000.00,    // Token Total Supply
                        _Balance : 100000000.00,    // Initial Balance before sale
                           _Name : "MyFirstToken",  // Token Name. It must match the project name in the settings 
                         _Symbol : "MFT",           // Asset Tiker.It must match the one in the settings 
                          _owner : "Owner address", // Asset Owner Address
                  
                    _constructor: function() {}
                  };'
```

Before diving into token operations, our first step is to focus on the constructor code. Here, we typically execute the <mark style="color:yellow;">Token Generation Event (TGE)</mark>, transferring all initial tokens to the rightful owner. This can be easily accomplished using the <mark style="color:yellow;">CRC\_Wallet class</mark>, as we’ve recently explored.

```javascript
_constructor: function() {
      
      // Create a new wallet instance
      var Owner = Object.create(CRC_Wallet); 
      
      // Loads the Owner's Wallet
      Owner.OpenWallet(this._owner);
      
      // Assignes the total Supply to the Owner
      Owner.Balance = this._TotalSupply;
      
      // Updates the Owner's wallet
      Owner.CloseWallet();
    }
```

\
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:\


<mark style="color:green;">**\_\_GetTotalSupply:**</mark> Retrieves the total token supply.

<mark style="color:green;">**\_\_GetCirculatingSupply:**</mark> Provides the number of tokens sold so far.

<mark style="color:green;">**\_\_GetTokenName:**</mark> Returns the token’s name.

<mark style="color:green;">**\_\_GetTokenTicker:**</mark> Retrieves the token’s ticker symbol.

With this understanding, let’s implement these functions, which should take no more than 10 minutes.



```javascript
__GetTotalSupply: function () {

    // we print on the smart contract output the total supply       
    println('TotalSupply : ' + this._TotalSupply );
    
    // we return it in case we wish to use internally
    return this._TotalSupply;
},
    
  
    
__GetCirculatingSupply: function () {
    
    // priting the circulating supply info
    println('CirculatingSupply : ' + (this._TotalSupply - this._Balance));
  
    // we return for internal uses
    return this._TotalSupply - this._Balance;
},


__GetTokenName: function () {
    
    // priting the Token Name
    println('Token Name : ' + this._Name);
  
    // we return for internal uses
    return this._Name;
},    


__GetTokenSymbol: function () {
    
    // priting the Token Symbol
    println('Token Symbol : ' + this._Symbol);
  
    // we return for internal uses
    return this._Symbol;
}, 
```



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.

```javascript
/* In debugging mode we need to invoke the constructor manually */
CRC_Contract._constructor();

CRC_Contract.__GetTotalSupply();
CRC_Contract.__GetCirculatingSupply();
CRC_Contract.__GetTokenName();
CRC_Contract.__GetTokenSymbol();
```



If everything is executed correctly, the output should resemble the following example:

\<Image>
