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
twitter （ It takes ）
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 .
After finding , Click on the contract address below
ok, Here's the code
Copy the code in it , By file , writes remix in , as follows ：
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
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 .
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 ：
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 .
Everything is ready. , that , Click on Deploy Release button , The fox confirmation box will pop up , This will consume GAS FEE,
Click on the confirmation , We'll see remix There are the following output on the console of ：
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 ：
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 ：
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
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
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 ;
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
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
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
We click on the link above , See why this deal failed ：
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
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 ,
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 .
see hhhhh Account number CTB, No, CTB, First add the token
see CTB balance , Sure enough 500 individual
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 .
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 .
Click on Verify And Publish, choice Compiler type 、solidity edition 、 Open source certificate type , Click to continue
Upload files ：
After uploading the file , Pull to the bottom , After man-machine Authentication , Click on Verify And Publish
Wait a moment ,ok, Source code upload complete .
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
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 .