Solidity学习笔记

Solidity学习笔记

基本类型

  1. uint
  2. bool
  3. address
  4. string

修饰符 modifier

  1. public
  2. private
  3. view
  4. pure

自定义modifier

// creator 需事先定义并初始化
modifier onlyCreator{
    require (msg.sender == creator)
    _;
}

mapping

mapping (address => uint256) public balances;
mapping (address => AddrBean) public userInfo;
mapping (address => bool) public userRegistered;

其中AddrBean是自定义的结构体struct

结构体struct

struct AddrBean{
    address parent_user;
    address grand_user;
}

函数

function myfunc(address addr) public view returns(unit256 amount){

}

合约接收Ether

function () external payable{
    balances[msg.sender] += msg.value;
}

合约发送Ether

//这里带余额检验,其中balance是合约内存储的地址的余额
function withdraw(uint256 amount) public payable{
    require(amount > 0 && balances[msg.sender] >= amount);
    msg.sender.transfer(amount);
    balances[msg.sender] -= amount;
}

Solidity 开发文档

Leave a Comment

豫ICP备19001387号-1