Ethereum practice sorting (III) Remix development and deployment of smart contracts

zhutianxiang 2021-09-15 11:29:57 阅读数:264

ethereum practice sorting iii remix


except Geth This is relative “ heavy ” The Ethereum client , There is another comparison ” light “ The client of : wallet . The wallet that ordinary users use more is imToken etc. , The wallet that developers often use is MetaMask:

MetaMask Is the easiest way to interact with Ethereum in a browser , It is a browser plug-in ( Support Chrome、FireFox、Opera Other browsers ), You can talk to Remix In combination with , Used to deploy and execute smart contracts .

visit MetaMask Official website Install the corresponding browser plug-in , After the account is imported or created , You can get into MetaMask main interface , The network can be switched in the upper right corner :

 screenshots 2021-09-09 In the morning 12.36.51.png


Remix It is a software that can be written online quickly 、 Editor for debugging and deploying contract code , It is very suitable for beginners of smart contract development .

We use a simple counter contract to demonstrate Remix General usage of .

visit Remix IDE:

Contract writing

Toolbar cut to FILE EXPLORERS, Create contract documents counter.sol:

Remix Create a contract .png

The contract code is as follows :

pragma solidity ^0.5.0;
contract Counter {
uint counter;
constructor() public {
counter = 0;
function count() public {
counter = counter + 1;
function get() public view returns (uint) {
return counter;

The function of this smart contract is to store a counter variable on the blockchain , Anyone can call count() Let the counter add 1, call get() Get the counter value .

Contract compilation

Toolbar cut to SOLIDITY COMPILER, Select the compiler version matching the code and click the compile button to compile , Compilation appears CONTRACT term , as follows :

Remix Compile contract 1.png

You can check auto compile , After the code is updated, it will be compiled automatically . Complex code , When there are many dependent files , It is not recommended to turn on automatic compilation .

Contract testing

Toolbar cut to SOLIDITY UNIT TESTING, Click on Generate Automatically generate unit test files counter_test.sol, Click on Run Run unit tests :

Remix Test contract 1.png

You can adjust the unit test code according to the situation , Conduct adequate testing .

Contract deployment and operation

The toolbar switches to DEPLOY & RUN TRANSACTIONS, choice JavaScript VM Deploy contracts in a sandbox environment :

Remix Deployment contract .png

The deployment contract will submit the transaction that created the contract , The trade will be mined and packaged in a block , You can see the deployed transaction details in the debugging information area below the code area :

Remix Deployment contract 2.png

After the smart contract deployment is completed , The deployed address and contract will appear at the bottom of the function area, and all functions that can be called :

Remix Deployment contract 3.png

Click on count and get Button can call the corresponding contract function .Remix An orange button is used to indicate that the action will modify the blockchain status , Blue indicates that the call is only to read the blockchain status .

After calling the function, the debug information area has output , You can click on the DEBUG, Step by step debugging the code .

Deploy to Ethereum network

When I use the sandbox environment to write and test the contract code , You can also choose to deploy to Ethereum private chain network according to the situation 、 Ethereum test network or Ethereum main chain network :

  • JavaScript VM: Sandbox environment , No interaction with Ethereum network ;
  • Injected Web3: Use the running environment embedded in the browser , Often use MetaMask The environment provided by the plug-in interacts indirectly with the Ethereum network ;
  • Web3 Provider: It means directly interacting with the real Ethereum network environment ;

Let's use Injected Web3 Mode deployment :

We are MetaMask After selecting the corresponding Ethereum network environment , Let's go back to Remix, Environmental choice Injected Web3, Will automatically load MetaMask account number :

Remix Deploy Ethereum .png

Click on Deploy Button , The transaction confirmation page pops up , Used to confirm the transaction content and gas Consume :

Remix Deployment confirmation .png

Click OK to submit the transaction , You can view the transaction status in the debugging information area .

After contract deployment , And in JavaScript VM In the same environment , The address after smart contract deployment will appear at the bottom of the functional area , And all functions that can be called in the contract .

Mist And Ethereum Wallet

Mist It's a DApp Browser , You can access any Ethereum DApp.Ethereum wallet It's an Ethereum wallet , It can be seen as a Mist The browser contains the only wallet DApp.Ethereum wallet Besides being a GUI wallet , It also includes smart contract publishing function .

Download address :

at present ,Ethereum Wallet And Mist They're still there 0.x edition , It's still in the fast iteration phase . It's not very convenient to use many times , The waiting time for some operations is long , Even the interface is stuck 、 Problems such as unable to close .

If it's an urgent task , Other methods are recommended , For example Remix collocation MetaMask Do the test on the Ethereum test network , use Truffle coordination Ganache Do local tests .