Now look at each rule in detail. We will start from optional to mandatory rules.
1. Token Name : CCN Token
This defines name of the token (here CCN Token) that would be created. It may be useful for various token trackers like etherscan to show token name.
2. Decimal : 18
It is the most confusing part. What is it and why we should define it. We would understand it by an example illustration.
Technically,
1 ETH = 1,000,000,000,000,000,000 (Uint256)
You can see 1 ETH in actual is a big number followed by 18 zeroes (or 1x 10^18). Now these 18 zeroes has become a standard notation and used to show decimal point by etherscan.io, metamask etc.
To make your life easier while transferring 1 ETH you just have to insert “1” and another 18 zeroes are internally added by metamask or myetherwallet to convert your “1” to actual number, i.e., “1,000,000,000,000,000,000”. But token trackers, wallets etc. consider these 18 zeroes as decimal points to show you
“1” ETH = 1.00000….0000 (18 zeroes)
“0.1” ETH = 1.00000….000 (17 zeroes)
“1.02” ETH = 1.02000….0000(16 zeroes)
And so on.
So if you choose decimals as 18 while creating your tokens you must know that your 1 token will actually be a big number where 1 is followed by 18 zeroes,i.e., “1,000,000,000,000,000,000”. The concept may become more confusing to interpret if you change decimal from 18 to something else. We will learn in deep about this in next article and this is enough today.
Fact: Actually, There is no decimal or floating point possible with smart contracts. They are always an integer. This should be taken care while using division in smart contracts or it could left anonymous bug in your code that we at CCN analyses for the purpose auditing.
3. Total Supply : 1000
Total supply identify the number of tokens that should be created. Here we are creating 1000 CCN tokens. Moreover this supply must be multiplied by decimal to make it work in actual.
For example if decimal is 18 then actual total supply must be 1000x(10^18) = 10^20
4. Symbol : CCN
Symbol defines the short for your token name. It shouldn’t be more than 3 or 4 characters.
Coming To some important and required methods and events to make your token ERC-20 compliant.
1. transfer method :
Transfer function allows to transfer your tokens from one wallet to another wallet.
2. balanceOf metod :
This method allows you to check available token balance of any address. Always use view modifier so it would not charge any gas fee when you call this method.
3. transferFrom method :
This method allows you to access someone else tokens to transfer on their behalf just same as proxy call. However it is must you have approval from the owner of wallet whose tokens you are going to access.
4. approve method :
approve method allows you to provide approval to access your tokens by someone else.
Sarcastic Fact: I actually didn’t know what this function does for an year until I had a requirement to access someone else tokens. 😅
5. allowance method :
allowance method allows you to check how much tokens approval is given to you by someone else to access their tokens.
6. Approval Event:
Whenver you approve some tokens to any ethereum wallet it is emitted to log that you have provided approval of tokens to someone else.
7. Transfer Event:
It is triggered on transfer of tokens.
You can read more about these methods and events here.
https://theethereum.wiki/w/index.php/ERC20_Token_Standard
ERC-20 is not only protocol that is accepted by ethereum community. There are various other protocols built over Ethereum that have different purpose and usage but ERC-20 is mostly used protocol. There is great article written on cointelegraph about those protocols and their usage.
Source: Crypto New Media