Michael Fawole
Michael Fawole

Follow

Michael Fawole

Follow
How to name your token in solidity

Photo by Pierre Borthiry - Peiobty on Unsplash

How to name your token in solidity

Naming token in solidity for beginner.

Michael Fawole's photo
Michael Fawole
·Oct 11, 2022·

2 min read

Play this article

Hello readers, in this article, I will be showing you how to create your own token with name, symbol and decimal in solidity. This is for beginner level.

The first step to take is to declare all your state variables like this:

pragma solidity ^0.5.0;
contract tech4dev{

string public name;
string public symbol;
uint public decimal;

    }

Let me explain the above code. name is set to string and public because string is the data type used for alphabet and alpha-numeric. uint is the data type used for numbers.

Next is to create a constructor. Constructor in solidity is a function which set the variables saved in it permanent on the blockchain. Constructor only run once and that is when you are deploying the contract for the first time.

constructor() public{

}

That is how constructor is defined.

See full code below.

pragma solidity ^0.5.0;
contract tech4dev{

string public name;
string public symbol;
uint public decimal;

constructor() public{

}

    }

Next step is to write the values of the variables inside the constructor.

constructor() public{
name = "Michael Token";
symbol = "MKT";
decimal = 18;
}

So we set the name to Michael Token, symbol to MKT and decimal to 18.

See the full code below.

pragma solidity ^0.5.0;
contract tech4dev{

string public name;
string public symbol;
uint public decimal;

constructor() public{
name = "Michael Token";
symbol = "MKT";
decimal = 18;
}

    }

Let compile and deploy the contract.

image.png

 
Share this