anthonyche / TechFantasy.Github.io

Zen of Tech
3 stars 0 forks source link

First smart contract #16

Open anthonyche opened 2 years ago

anthonyche commented 2 years ago

第一个使用 Remix IDE 部署的智能合约

public 这种声明会加在通常python常见的声明之后

    pragma solidity ^0.4.24;

    contract MyContract{
        string value;
        # contract类似class
        constructor() public {
            value = "myValue";
        }

        function get() public view returns(string){
            return value;
        }

        function set(string _value) **public** {
            value = _value;
        }

    }
anthonyche commented 2 years ago
    pragma solidity 0.5.1;

    contract MyContract{
        // string public constant stringValue = 'myValue';
        // bool public mybool = true;
        // int public myInt = -1;
        // uint public myUint = 1;
        // uint8 public myUint8 = 8;
        // uint256 public myUint256 = 25886;
        enum State {Waiting, Ready, Active}
        State public state;

        constructor() public{
            state = State.Waiting;
        }

        function active() public{
            state = State.Active;
        }

        function isActive() public view returns(bool){
            return state == State.Active;
        }

    }
anthonyche commented 2 years ago
    pragma solidity 0.5.1;

    contract MyContract{
       Person[] public people;
       uint256 public PeopleCount;

       struct Person{
           string _firstName;
           string _lastName;
       }

       function add_person(string memory _firstName, string memory _lastName) public {
           people.push(Person(_firstName,_lastName));
           PeopleCount +=1;
       }

    }