CRYPTOCURRENCY

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 Ethereum user and the ERC20 Token standard, you are probably curious how to use these concepts without having initial balance. In this article, we will translate you through the process of using ERC20 markers when all balances are 0.

Understanding ERC20

Before we dive, let’s quickly review what ERC20 is. The ERC20 standard defines a marker that can be used as an Ethereum blockchain currency. This is a simple sign of no inherent value, which means that its value is extracted from the demand and supply of the market. In other words, tokens such as ether (ETH) or USDC are not supported by a physical asset.

Run ERC20 by Openzepelin

To use ERC20 markers, you will need to consult the OpenZeppelin contract that implements this standard in your Ethereum network. The specific conversion we will use is accessible at [ TRACTS/BLOB/AE1BAFCB48FE220257D76BFD93A237DB3BAF3DF/Contracts/Token /erc20/erc20.sol).

Step 1: Create a token ERC20

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

To start using ERC20 markers, you will need to create a new marker contract. This includes defining the marker metadata, such as its name and symbol.

`Solidness

Pragma Solidity ^0.8.0;

Contract MyToken {

String public name = “my token”;

String public symbol = “myt”;

}

`

Step 2: Initialize the tokena

You will then need to initialize your marker contract using the Nova feature provided by Openzepelin.

`Solidness

Pragma Solidity ^0.8.0;

Contract MyToken {

// …

constructor () {

_inittoken ();

}

Function _inittoken () internal {

Mytakeninitializer.init (_tacknaddress);

}

}

Structure MyTeKeninitializer {

Address _TeKenaddress;

}

`

Step 3: Unleash the tokens contract

Now that your marker contract has been initialized, you can implement it into the Ethereum network by using the tool to deploy solidity.

`Solidness

Pragma Solidity ^0.8.0;

Contract MyToken {

// …

Function deploy () public returns (address) {

Address NewTeKenaddress = MyTeKeninitializer._TeKenaddress;

Return NewTeKenaddress;

}

}

`

Step 4: Set the marker delivery

To set the delivery of markers, you will need to create a mapping that maps the name of the marker to its common delivery.

`Solidness

Pragma Solidity ^0.8.0;

Contract MyToken {

// …

Uint Public Atallasupply;

mapping (string => uint) publicly Nametosupply;

Settotalsupply function (uint _totalsupply) public {

Outalsupply = _totalsupply;

for (address tokensymbol in Nametosupply.Values ​​()) {

If (tokensymbol! = address (this)) {

Uint Supplyamount = Nametosupply [tokensymbol]_ Totalsupply / 10 * ۱۸;

Deleting Nametosupply [tokensymbol];

}

}

}

Getbalanceof (Address _Account) Public View Returns (Uint256) {

Return athapsupply – Nametosupply [_Account];

}

// …

}

`

Step 5: Use tokena

Finally, you can use your toilet as usual by calling the ‘Balanceof’ feature to check his balance or use it to transfer ether.

`Solidness

Pragma Solidity ^0.8.0;

Contract MyToken {

// …

Constructor () {}

Function Deposit (Address _Account, Uint Sum) Public Declarations (Uint256) {

Totalsupply += Nametosupply [_Account]sum / 10 * ۱۸;

Return athapsupply – Nametosupply [_Account];

}

Download function (UINT) Public Declaration (Bool) {

require (Staralsupply> = sum);

Totalsupply -= Nametosupply [msg.sender]sum / 10 * ۱۸;

// …

monero fundamental analysis

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *