Introduction to Remix

Integrated development IDE for writing and interacting with smart contracts

Remix - Ethereum IDE

Using the Solidity plugin

Start writing Solidity code

In any smart contract, you need to declare the version of Solidity and define a license. Generally, the MIT protocol is used. Some compilers will report an error if they do not write a license.

// SPDX-License-Identifier:MIT

pragma solidity 0.8.7; //^0.8.7 更新的版本 >=0.8.7 < 0.8.12 使用一定范围内的版本

Click to compile this file

Define the smart contract part:

contract SimpleStorage{



}

Deploying smart contracts: Deploying a contract is actually sending a transaction. When we do anything on the blockchain and modify any state, we just send another transaction and deploy a contract, which modifies the blockchain and allows the contract to be on the chain. , to deploy a contract on the main network, you need to pay gas

Every time we change the state of the blockchain, we send a transaction


 

// SPDX-License-Identifier:MIT

pragma solidity 0.8.8; //^0.8.7 更新的版本 >=0.8.7 < 0.8.12 使用一定范围内的版本







contract SimpleStorage{



uint256 favoriteNumber;







function store(uint256 _favoriteNumber) public{



favoriteNumber = _favoriteNumber;



}

}



The more steps a function has, the more gas it consumes

// SPDX-License-Identifier:MIT

pragma solidity 0.8.8; //^0.8.7 更新的版本 >=0.8.7 < 0.8.12 使用一定范围内的版本







contract SimpleStorage{



    uint256 public favoriteNumber;







    function store(uint256 _favoriteNumber) public{



        favoriteNumber = _favoriteNumber;



        favoriteNumber = favoriteNumber+1;



    }





    function retrieve() public view returns(uint256){



        return favoriteNumber;



    }

}

The keyword view identifies that the call to the function does not need to consume gas. The view keyword means that only the status of the contract will be read and no modification of any status is allowed.

The keyword view identifies that the call to the function does not need to consume gas. The view keyword means that only the status of the contract will be read and no modification of any status is allowed.

The keyword pure is not allowed to modify any status, nor is it allowed to read the contract status. It can only perform algorithms, and the function indicating pure does not need to pay gas.

Calling the view and pure functions is free, unless you call it in a gas-consuming function such as the store function. At this time, reading the blockchain information consumes calculation and gas.

Guess you like

Origin blog.csdn.net/woshiyuyanjia/article/details/134667398