[Ethereum Development-02] Basic use of remix

Remix

Remix is ​​both an editor and a compiler . It is an editor that can quickly write, debug and deploy contract codes online. It is very suitable for beginners in smart contract development.

We demonstrate the general usage of Remix with a simple counter contract.
Visit: remix

Contract creation and writing:

Switch to FILE EXPLORERS on the toolbar , create a contract file firstContract.sol:
insert image description here
write a simple contract:

pragma solidity ^0.4.24; 
contract Inbox{
    
     
    string public message; 
    function Inbox()payable {
    
     

    }
    function setMessage(string newMessage) public{
    
     
        message = newMessage; 
    }
    function getMessage() public constant returns(string){
    
     
        return message; 
     } 
}

The role of this contract is to store a variable message on the blockchain. Anyone can assign a value to the variable by calling setMessage() and get the value by calling getMessage().

Contract Compilation

Switch to SOLIDITY COMPILER on the toolbar, select the compiler version that matches the code, and click the compile button to compile. The CONTRACT item appears after compiling, as follows:
!](https://img-blog.csdnimg.cn/e568d821ba4845ce871fdf8533c9d802.png)

Contract deployment:

Deployment of the VM environment:

Switch the toolbar to DEPLOY & RUN TRANSACTIONS , and select the JavaScript VM environment to deploy the contract:
insert image description here

So far a contract has been successfully created. Deploying a contract will submit a transaction for creating a contract (creating a contract itself is a transaction, but this transaction has no receiver), and the transaction will be mined and packaged in a block, which can be seen in the debug information area below the code area. Transaction Details:

Deployment of the test network

insert image description here

Call the contract function

insert image description here

In Remix, an orange button is used to indicate that the action will modify the state of the blockchain, and blue means that the call is only to read the state of the blockchain. The call of the contract is equivalent to a tx, and the read operation is free, and the set action needs to change the state of the blockchain, which requires gas fees.

References:

https://segmentfault.com/a/1190000040657797?utm_source=sf-similar-article

Guess you like

Origin blog.csdn.net/weixin_42918559/article/details/125049201