第76篇 Faucet 智能合约

Posted wonderBlock

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第76篇 Faucet 智能合约相关的知识,希望对你有一定的参考价值。

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 编译部署通过,仅供参考。

以上是关于第76篇 Faucet 智能合约的主要内容,如果未能解决你的问题,请参考以下文章

第146篇 笔记-智能合约介绍

第113篇 笔记-DateTime智能合约

第91篇 笔记-物流溯源智能合约

第115篇 智能合约的代理升级模式

第124篇 NFT市场智能合约

第89篇 defi实战-质押ERC20智能合约