solidity 合约代码,demo

pragma solidity ^0.8.0;
contract SimpleStorage {
    
    uint public storedData;
    
    address  public  owner=0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
    
    uint256 public money;
    
    address public thisAddress=address(this);
    address public thisAddress2=msg.sender;
    
    uint public etherTest=1 gwei;
    
    mapping(address => uint256) public balances;
    
    
    
    
    event Set(uint x);//事件
    
     enum State { Created, Locked, InValid } // 枚举
     
     State public state;


    
    
    modifier onlyOwner(){
       require(owner == msg.sender,"only owner can call this function");
       _;
    }
    
    
    struct Voter { // 结构体
        uint weight;
        bool voted;
     
    }
    
    
    Voter[] public voter;
    
    function set(uint x) public onlyOwner {
        storedData = x;    // 错误的,多加了一个加号
        emit  Set(storedData);
    }
    
    function setState(State _state) public{
        
        state=_state;
    }
  
    
    function f(uint len) public pure {
        uint[] memory a = new uint[](7);
        bytes memory b = new bytes(len);

        assert(a.length == 7);
        assert(b.length == len);

        a[6] = 8;
    }
    
    function setVoter( uint _weight,bool _voted) public {
        
        voter.push(Voter(_weight,_voted));
    }
    
    function bal()   public   view returns(uint){//返回余额
        return msg.sender.balance;
    }
    
    function testPure(uint x)   public   pure returns(uint){//纯
        return x*2;
    }
    
    function buy() public payable{
        assert(msg.value>0);//必须大于0,不然不执行下面的
        money+=msg.value;
    }
    
    function mint(address account,uint256 amount) public onlyOwner{//铸币,当前账号才有权限
        balances[account] += amount;
    }
    
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值