Tue. Sep 21st, 2021

One of the most significant smart contract standards on Ethereum is known as the ERC-20, which emerged as a technical standard used for all smart contracts on the Ethereum Blockchain for the implementation of Fungible Token.

ERC-20 defines a list of general rules that must be obeyed by all fungible mint erc20 tokens. As a result, this standard token empowers developers of all types to accurately predict how new tokens will function in larger etherum systems. It simplifies and facilitates the task of the developer, because they can continue their work, knowing that every new project does not need to be renovated every time a new token is released, as long as the token follows the rules.

The following, presented as an interface, the ERC-20 function must apply. If you are unsure about what interface: Check our article about OOP programming in solidity.

Pragma Solidity ^ 0.6.0;

IERC20 Interface {

TotalSuply function () Returns External Display (UInt256);
Balance function (address account) view external return (UInt256);
Function allowance (address owner, address spender) View external returns (uint256);

Transfer function (receiver address, number of uint256) external refund (bool);
approve function (spender address, number of uint256) external refund (bool);
TransferFrom function (address sender, receiver address, number of uint256) external refund (bool);


Event transfer (addressed address of, addressed address to, uint256 value);
Event approval (indexed owner address, indexed spender address, uint256 value);
}

The following are line-by-line browsing about what each function does. After this, we will present a simple implementation of the ERC-20 token.

Getters.

TotalSuply function () Returns External Display (UInt256);

Returns the number of tokens. This function is a takeover and does not modify the state of the contract. Keep in mind that there are no buoys in solidity. Therefore most tokens adopt 18 decimals and will refund the total supply and other results as follows of 100 billion to 1 token. Not every token has 18 decimals and this is something you really need to watch when dealing with tokens.

Balance function (address account) view external return (UInt256);

Returns the number of tokens owned by the address (account). This function is a takeover and does not modify the state of the contract.

Function allowance (address owner, address spender) View external returns (uint256);

The ERC-20 standard allows addresses to provide benefits to other addresses to retrieve tokens from it. This takeover returns the number of tokens remaining that spenders will be allowed to spend on behalf of the owner. This function is a takeover and does not modify the state of the contract and must return 0 by default.

Function

Transfer function (receiver address, number of uint256) external refund (bool);

Move the number of tokens from the caller’s address function (msg. sender) to the recipient’s address. This function emits the transfer event specified later. This returns true if the transfer is possible.

approve function (spender address, number of uint256) external refund (bool);

Set the number of allowances allowed to be transferred from the caller function balance (msg. sender). This function emits an approval event. The function returns whether the allowance is successfully arranged.

TransferFrom function (address sender, receiver address, number of uint256) external refund (bool);

Transfer the number of tokens from the sender to the recipient using the preliminary mechanism. The number is then deducted from the caller allowance. This function emits a transfer event.

Event

Event transfer (addressed address of, addressed address to, uint256 value);

This event is transmitted when the number of tokens (value) is sent from the address to the address.

In the case of new minting tokens, transfers are usually from 0x00.0000 a