Ethereum: How can I use ERC20 for the first time when all balances are 0?

Using ERC20 for the First Time With 0 Balance: Step -by -Step Guide

As a new user of Ethereum and ERC20 -token, you are probably curious about these concepts are used without original balances. In this article, we will learn you through the use of ERC20 chips when all balances are 0.

Understanding ERC20

Let’s look quickly before diving what erc20 is. The ERC20 Standard Defines a ID that can be used as a currency in the Ethereum Block Chain. It is a simple sign that has no natural value, which means that its value is derived from market demand and supply. In other words, the tokens such as ether (ETH) or USDC are not supported by any physical property.

ERC20 Implementation of Openzeppelin

In order to use the ERC20S, you need to contact the openseppelin agreement that implemented this standard on ethereum. The special implementation is available at [ TS/Token /erc20/erc20.Sol).

Step 1: Create ERC20 ID

To start using ERC20, you need to create a new character agreement. This includes defining token’s metadata, such as its name and symbol.

`Solidity

Pragman Solidity ^0.8.0;

Agreement mytoken {

string public name = “my token”;

string of public symbol = “myt”;

}

`

Step 2: Start Character

Next, you need to introduce the ID Agreement with the “New” feature provided by Openzeppelin.

`Solidity

Pragman Solidity ^0.8.0;

Agreement mytoken {

// …

Builder () {

_Initochen ();

}

Function _initoken () internal {

Mytokeninitializer.Inin (_tokenaddress);

}

}

Struct mytokeninitializer {

Address _tokenaddress;

}

`

Step 3: Start the Token Agreement

Now that your character contract is being formatted, you can enable it to the Ethereum Network using the Solidity Deployment Tool.

`Solidity

Pragman Solidity ^0.8.0;

Agreement mytoken {

// …

Function Use () Public Return (Address) {

Address Newtokenaddress = mytokeninitializer._tokenaddress;

Restore Newtokenaddress;

}

}

`

Step 4: Set the Characteristic

To set the token offer, you need to create an mapping that will map the name of the name for its overall assessment.

`Solidity

Pragman Solidity ^0.8.0;

Agreement mytoken {

// …

Uint public total number;

mapping (string => uint) public namotosupply;

Function Setotastalsupply (uint _totalsupply) public {

Totalsupply = _totalupply;

(address token symbol in namotosupply.values ​​()) {

if (token symbol! = address (this)) {

Uint scutamount = namotosupply [token symbol]_ Totalupply / 10 * 18;

namotosupply removes [Token Symbol];

}

}

}

Function Getbalanceof (Address _Ccount) Public View Return (Uint256) {

Return the total number – namotosupply [_ccount];

}

// …

}

`

Step 5: use token

Finally, you can use your token as usual by inviting the “balance” feature to check or use it to move the ether.

`Solidity

Pragman Solidity ^0.8.0;

Agreement mytoken {

// …

Builder () {}

Function Deposit (Address _ccount, Uint quantity) Public Returns (Uint256)

Total numbers += namotosupply [_account]quantity / 10 * 18;

Return the total number – namotosupply [_ccount];

}

Function Lifting (Uint Quantity) Public Returns (Punch) {

Require (total amount of the total> = quantity);

Total number -= namotosupply [msg.seender]Amount / 10 * 18;

// …

ETHEREUM INTEGER


Comentários

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *