introduce

Remix uses documentation

Remix is an open source, Web-side IDE for Solidity smart contract development that provides basic compile, deploy locally or test the network, execute contracts, and more. Solidity is an official programming language designed and supported by Ethereum specifically for writing smart contracts.

Remix can be deployed locally or directly using the officially deployed remix.ethereum.org address. The interface is shown as follows:

Create a token contract

The Solidity website has a simple Example of creating a token contract Subcurrency.

pragma solidity >0.424.;

contract Coin {
    // The keyword "public" makes those variables
    // easily readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react to
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    // Contract constructor. The contract creator is the minter when the contract is created
    constructor() public {
        minter = msg.sender;
    }
    
    // Only the contract creator can mint coins
    function mint(address receiver, uint amount) public {
        require(msg.sender == minter);
        require(amount < 1e60);
        balances[receiver] += amount;
    }
     
    // Send tokens
    function send(address receiver, uint amount) public {
        require(amount <= balances[msg.sender], "Insufficient balance.");
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount); }}Copy the code

This is the simplest token generation contract that does the following:

  1. Creation contract: stipulate that the creator is the minter
  2. Token generation: The contract author can call the mint method at any time to create a specified number of tokens
  3. Send tokens: As long as you own tokens, you can send tokens to the specified address

Compile the contract

  1. Create a. Sol contract file
  2. Writing contract code
  3. Begin to compile
  4. Compile successfully

Compile the Details generated by the contract

Once the contract is successfully compiled, click the Details button and you’ll see some of the compiled information, as shown below:

  1. NAMEName: contracts
  2. METADATACompile information, such as version, language used, Settings, etc
  3. BYTECODE: Writes the bytecode to the block
  4. ABI: This smart contract corresponds to the ABI, which is the interface defined in our contract
  5. WEB3DEPLOY: smart contract compiled after the release command, this is more important, later Web3 is to call this command to deploy the contract
  6. METADATAHASH: a hash of the 2 metadata above
  7. SWARMLOCATIONSwarm: an address of the Swarm network (What exactly is Swarm)
  8. FUNCTIONHASHES: the hash of the method defined by the contract. In fact, we use this hash to find the corresponding method to execute the contract
  9. GASESTIMATES: A budget for miner’s fees. The deployment and execution of contracts on ETH require miner’s fees. Generally, the more contract codes, the higher the miner’s fee.

Local Deployment Contract

  1. Click Run in the upper right corner
  2. The selected deployment environment is local (i.e. the contract will not be deployed to a public blockchain network, only to a local test blockchain network)
  3. Select the deployment account (by default, several accounts will be created in the local environment, each account has 100 ETH by default)
  4. Select the contract to deploy
  5. Click Deploy to Deploy locally
  6. Contract address after deployment

Alternatively, enter the deployed contract Address in At Address. The contract with the corresponding Address is displayed in 6.

Test the network deployment contract

First, install the MetaMask plugin and download it from the Chrome Store. This is an Ethereum wallet plugin for Chrome. The specific use is not explained here.

The test network I use here is Rinkeby, and the ETH token of the account on Rinkeby needs to be obtained from www.rinkeby.io/#faucet.

We specially selected Injected Web3 on the test network and Remix will automatically connect to MetaMask. We can see that the account has also become our MetaMask account.

Finally click Deploy, MetaMask will pop up and ask you to make a confirmation, because the deployment contract requires a miner fee, which is basically confirmation of the miner fee. After confirmation, an announcement will be made, the miner will collect the miner fee, and the contract will be deployed to the block.

Call the contract

After the contract deployment is completed, the contract we have deployed will appear below, or we can directly fill in the At Address with the Address of the contract that has been deployed before.

Expanding the contract, we can see some of the methods and variables we defined in the previous contract code. Mint and SEND are executed with miner fees.

  1. Mint generates tokens: Fill in the account address (need to be the address of the contract creator) and the number of tokens generated, clicktransactExecute contract code.
  2. Send send token: After expanding, fill in the recipient’s account address and the number of tokens received
  3. Check the token balance in the corresponding address
  4. View the minter (contract creator)

Terminal output

View transaction details

In the process of contract deployment and execution, the terminal output will output corresponding content information. Here is the output of a contract deployment (hash marked with transfer, contract creator, gas charge, input, etc.) :

The Debug debugging

Debugging needs to be conducted in the local environment, that is, select JavaScript VM during contract deployment, and then click the Debug button on the right of the corresponding transaction in the terminal output as shown in the figure above, the debugging interface as shown below will be displayed:

PS: It is possible to enter Block number and TxHash directly to check the call stack, but I found empty after entering, I don’t know why.