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 編譯部署通過,僅供參考,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/287446.html
標籤:區塊鏈
上一篇:有哪些專案需要用到性能優化技術
