Faucet 在以太坊网络称为水龙头,它向任何提出申请的地址发送底层币。
1. faucet1.sol
pragma solidity ^0.4.19;
contract Faucet {
// Give out ether to anyone who asks
function withdraw(uint withdraw_amount) public { // 提币函数
// Limit withdrawal amount
require(withdraw_amount <= 100000000000000000); // 每次限额
// Send the amount to the address that requested it
msg.sender.transfer(withdraw_amount); // 发币
}
// Accept any incoming amount
function() public payable { // 回退函数,可以接收底层币
}
}
2. faucet2.sol
升级版合约:
pragma solidity ^0.8.0;
contract Faucet {
function withdraw(uint withdraw_amount) public {
require(withdraw_amount <= 100000000000000000);
payable(msg.sender).transfer(withdraw_amount);
}
fallback() payable external {}
receive() payable external {}
}
本文合约在 remix 编译部署通过,仅供参考。