Entry blockchain, starting with issuing currency

Maca 2021-04-01 22:00:15 阅读数:649

本文一共[544]字,预计阅读时长:1分钟~
entry blockchain starting issuing currency

 picture

Recently, there are more news in the currency circle , I've been frying money for so long , But I don't know how the coin came into being , We as procedural apes , It's a little humiliating , Don't talk much , Let's issue a coin , Name is CodeToken, abbreviation CTB.

Because of the money , Deploy , Transfer and so on are all consuming GAS FEE(GAS FEE What is it? ?GAS FEE It can be understood as service charge ) Of , So we're testing online coin issuance , The choice of test network here is Rinkeby, First of all, you're going to https://faucet.rinkeby.io/ Coin , The steps are very clear .

The preparation of the instruments

  • Online Compiler remix:https://remix.ethereum.org/

  • Browser block :https://etherscan.io/

  • rinkeby Test network block browser :https://rinkeby.etherscan.io/

  • MetaMask Wallet plug-in

  • VPN

  • twitter ( It takes )

1. code

Open the Ethereum block browser (https://etherscan.io/ ) . If it doesn't open , need VPN( The official account replied VPN, Get free unlimited traffic VPN) Oh , We search for a hot currency before ,YFII( Second uncle ), Anyone who believes in money speculation knows , It's a rare hundred times , A lot of .

 picture

After finding , Click on the contract address below

 picture

ok, Here's the code

 picture

Copy the code in it , By file , writes remix in , as follows :

 picture

The code follows the standard ERC20 agreement . I've annotated all the code , It's convenient for friends to check , meanwhile , The code is also uploaded to Github:https://github.com/joeBeckham/codeToken

2. compile

When the code is finished , We're going to compile it , Let's see if there's a problem with the code .

First, let's be clear , Our main contract is CodeToken, When compiling, you should select CodeToken.sol file , And then choose remix The compile button on the left side of the , choice solidity After version , Click on the Compile CodeToken.sol Button , When the compiler passes , You will find that the compile button on the left has a check mark , meanwhile , A new file button will be added artifacts Folder , It contains compiled files .

 picture

3. Deploy

Compilation passed , The next step is to deploy .

First , To be clear ,remix The third button on the left is the Publish button . Click the Publish button , Will see that there is ENVIRONMENT、ACCOUNT 、GAS LIMIT、CONTRACT etc. .

among ,ENVIRONMENT There are several options :

  • JavaScript VM: This is a Remix Your own internal sandbox . It doesn't connect to MainNet,TestNet Or any private network . This is an in memory blockchain , It can be used for simple testing and rapid mining .

  • Injected Web3: This is for browser plug-ins (MetaMask) The option to . ad locum ,Remix Give all control of the blockchain integration to MetaMask plug-in unit . here ,MetaMask Control the network you want to connect to .

  • Web3 Provider: This is allowed in Remix Input in URL To connect to the blockchain . The most common setting here is to run the local node and pass through it IP/ The port is connected to the node

ENVIRONMENT We choose Injected Web3.

ACCOUNT 、GAS LIMIT The default can be ,CONTRACT Then choose CodeToken.sol The main contract .

 picture

Everything is ready. , that , Click on Deploy Release button , The fox confirmation box will pop up , This will consume GAS FEE,

 picture

Click on the confirmation , We'll see remix There are the following output on the console of :

 picture

Contains the status of the transaction 、hash、gas Etc ,status We see it's successful , Let's take this transaction to the Ethereum block browser to check , Of course , To check in the Ethereum block browser of the test network , Copy transaction hash , then open https://rinkeby.etherscan.io/ , You'll see the details of the deal :

 picture

So how do we look at the contract for deployment ?

Copy From Address , Query in the block browser , Find the contract published at this address :

 picture

Click in and you'll see .

4. Verification contract method

After the contract deployment is completed , We're going to test the method . It's still the deployment menu , Click on > , Will see A bunch of things , Don't panic , Let's read

 picture

These are the variables and methods we define in the contract .

Click on totalSupply Variable , Let's look at released token Total amount , you 're right , yes 0, Because we haven't coined yet

 picture

just as CodeToken The code says the same , To coin (mint Method ), First of all Address with mint authority , If you want an address with mint permission , You have to add coin authority to an address first (addMinter Method ), Adding coin authority is not available to every user , Need to be governance administrator address (governance Variable ), Default governance administrator address (governance Variable ) Is the address user of the deployment contract , If you want to change the governance administrator address , Need to set governance administrator address (setGovernance Method ), This method requires the caller to be the current governance administrator address , That's how it's understood .

We're trying to sort it out again , Sum up two sentences :

  • Add coin authority to an address with the former administrator address ( use governance Address call addMinter Method )

  • Have the right to mint coins to the designated address ( use addMinter Method parameters perform mint Method )

Let's practice :

1. Switch Fox's account to the account we just released the contract ;

 picture

2. hold test The account number is set to have the right to coin , hold test Copy to address of addMinter In the box at the back , Click on addMinter box , Fox confirmed that , We see that the deal is a success

 picture

3. Under query test Whether the address of the account has the right to coin

take test Copy the address of the account to minters In the box at the back , Click on ,true, Verification passed

 picture

4. to mint , Use test The address of the account number is used to make coins 10000 individual

stay mint Enter the parameters in the following box 0xf43d31E51c78dEdDA5E12711401e3B516b207fB7,10000000000000000000000,10000 Back plus 18 individual 0, Because there is no decimal in the chain .

Click on mint Button , Fox confirmed that , We see that the deal is a failure

 picture

We click on the link above , See why this deal failed :

 picture

you 're right , The error is No miniter, Let's rub , We set it up test Account address Have the right to coin , however Our fox account number is nicegogogo account number , obviously ,nicegogogo We don't have the right to mint .so, Switch fox account to test account number

Re execution ,ok, Successful trade .

5. Look at the total amount of money , Click on totalSupply

 picture

Get rid of 18 individual 0, Total amount 10000, you 're right .

6. Test the transfer method

Use the current fox account (test account number ) Here it is hhhhh Account transfer 500 individual CTB, stay transfer Enter... In the following box :0x83B109CF083f0c8Bcc9ab07aF964B135Df325771,500000000000000000000, Click on transfer Button ,

 picture

We look at Fox's test account number , There should be 10000 individual CTB Of , Transfer accounts 500 After a success , The remaining 9500 individual .

 picture

see hhhhh Account number CTB, No, CTB, First add the token

 picture

see CTB balance , Sure enough 500 individual

 picture

5. Release source code

After the contract deployment test is completed , We turn on ETH Blockchain browser , Search for what we sent token,CTB, Be careful , This time token The contract address is 0x120d5ce8be6f65e51776086aefbb3f83b491b33c

When you search, you may find that there are two CTB, Because I sent one when I was testing .

 picture

Click on the contract address , And then choose Contract Options , Can't see our source code , And see Yes Verify And Publish, you 're right , It's because we don't have Upload code and open source .

 picture

Click on Verify And Publish, choice Compiler type 、solidity edition 、 Open source certificate type , Click to continue

 picture

Upload files :

 picture

After uploading the file , Pull to the bottom , After man-machine Authentication , Click on Verify And Publish

 picture

Wait a moment ,ok, Source code upload complete .

 picture

such , The entire contract is deployed and released . Out of remix In addition to calling methods , It can also be called in block browser , Search for just released currency CTB, After opening Will see Yes Read Contract and Write Contract

 picture

  • Read Contract It's the exposed readable variables and methods , You don't have to connect the wallet , No consumption GAS

  • Write Contract It's the modified variable and the modified method , To connect the wallet , Will consume GAS

This is what we released CTB The coin , We have achieved the standard ERC20 The interface in the protocol .

It's better to know how to make money than to fry money , Know what it is and know why it is , very NICE Oh .

 picture


 picture

版权声明:本文为[Maca]所创,转载请带上原文链接,感谢。 https://netfreeman.com/2021/03/20210330185811576B.html