Ethereum Faucet – 以太坊水龙头区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Ethereum Faucet – 以太坊水龙头区块链毕设代写 是一篇很好的国外资料

Ethereum Faucet

Description

This project is a basic Ethereum faucet that enables anyone to send Ether to the smart contract to fill it up with funds and you can interact with it through the withdraw function to request 0.1 ETH from the faucet.

If the faucet has enough funds you will receive 0.1 ETH to your Ethereum address. There is a simple timeout filter built in to only allow one request per 30 minutes.

Key Facts

  • This code is published under the MIT License
  • This code has been deveoped by Jacob Suchorabski
  • Solidity (v. 0.7.4) has been used to develop and test the faucet
  • Remix has been used as an IDE to develop this code

Requirements & Demo

This version of the smart contract is deployed on the Ropsten Testnetwork and you can find it with the following address:

0x5194d3D2D77585ff89a2823F77C191a93d2F6416

If you want to use the smart contract you will need an Ethereum Wallet that can interact with smart contracts and switch to the Ropsten Testnetwork (Example: MetaMask).

Features

Variables & Events

address owner; mapping (address => uint) timeouts;      event Withdrawal(address indexed to); event Deposit(address indexed from, uint amount);      constructor() {     owner = msg.sender; }  function destroy() public{ 		require(msg.sender == owner, "Only the owner of this faucet can destroy it."); 		selfdestruct(msg.sender); }
  • When creating the smart contract the owner will be saved in order to protect the selfdestruct method which destroys this smart contract and sends all remaining funds of the contract to the sender.
  • The timeouts hash map is used to track which address already used this faucet at which timestamp.
  • Withdrawal and Deposit are events that will be called in the functions described below to make sure that we store our transactions in the transaction log which can be accessed through the blockchain.

Withdrawing Ether

function withdraw() external{      require(address(this).balance >= 0.1 ether, "This faucet is empty. Please check back later.");     require(timeouts[msg.sender] <= block.timestamp - 30 minutes, "You can only withdraw once every 30 minutes. Please check back later.");      msg.sender.transfer(0.1 ether);     timeouts[msg.sender] = block.timestamp;      emit Withdrawal(msg.sender);      }
  • We are checking for two simple requirements in this project
    • Does this smart contract have enough funds? (This smart contract always sends exactly 0.1 ETH)
    • Did the sender already request a withdrawal in the last 30 minutes? (Checked using the timestamp of the current block of the transaction)
  • If those conditions are met 0.1 ETH are sent to the msg.sender which is the entity calling the smart contract
  • Finally the current timestamp is added to our timeouts hashmap

Donating Ether

receive() external payable { 		emit Deposit(msg.sender, msg.value);  } 
  • Ether can be donated by anyone by simply sending Ether to the smart contract
  • The receive() function is a default function that is payable so it can receive funds. You could also leave this function empty but since we want donations to be visible in the transaction log we are emitting our defined event.

Initial Release


以太坊eth水龙头

说明

这个项目是一个基本的以太坊eth水龙头,使任何人都可以发送以太到智能合约,以填补它的资金,你可以与它互动,通过提取功能,要求从水龙头0.1以太。

如果水龙头有足够的资金,您的以太坊eth地址将收到0.1以太币。内置了一个简单的超时过滤器,每30分钟只允许一个请求。

关键事实

  • 此代码根据MIT许可证发布
  • 此代码由Jacob Suchorabski开发
  • Solidity(v.7.4)用于开发和测试水龙头
  • Remix用作IDE,在创建将保存所有者的智能合约,以保护自毁方法,该方法将销毁此智能合约并将合约的所有剩余资金发送给发送者。

要求和演示

此版本的智能合约部署在Ropsten Testnetwork上,您可以通过以下地址找到它:

0x5194d3D2D77585ff89a2823F77C191a93d2F6416

如果您想使用智能合约,您将需要一个可以与智能合约交互并切换到Ropsten Testnetwork的以太坊eth钱包(例如:元掩码)。

功能

变量和;事件

address owner; mapping (address => uint) timeouts;      event Withdrawal(address indexed to); event Deposit(address indexed from, uint amount);      constructor() {     owner = msg.sender; }  function destroy() public{ 		require(msg.sender == owner, "Only the owner of this faucet can destroy it."); 		selfdestruct(msg.sender); }
  • 超时哈希映射用于跟踪哪个地址已经在哪个时间戳使用了这个水龙头。
  • 取款和存款是将在下面描述的函数中调用的事件,以确保我们将交易存储在可通过区块链blockchain访问的交易日志中。
  • 我们正在检查此项目中的两个简单要求此智能合约是否有足够的资金?(此智能合约始终精确发送0.1 ETH)发件人是否在过去30分钟内已请求取款?(使用当前交易块的时间戳进行检查)

提取乙醚

function withdraw() external{      require(address(this).balance >= 0.1 ether, "This faucet is empty. Please check back later.");     require(timeouts[msg.sender] <= block.timestamp - 30 minutes, "You can only withdraw once every 30 minutes. Please check back later.");      msg.sender.transfer(0.1 ether);     timeouts[msg.sender] = block.timestamp;      emit Withdrawal(msg.sender);      }
  • 此智能合约是否有足够的资金?(此智能合约始终精确发送0.1 ETH)
  • 最后,当前时间戳被添加到我们的超时hashmap中
  • 任何人都可以通过向智能合约发送以太来捐赠以太contract

捐赠乙醚

receive() external payable { 		emit Deposit(msg.sender, msg.value);  } 
  • receive()函数是一个默认函数,它是可支付的,因此可以接收资金。您也可以将此函数留空,但由于我们希望捐款在事务日志中可见,因此我们正在发出定义的事件。你知道吗
  • The receive() function is a default function that is payable so it can receive funds. You could also leave this function empty but since we want donations to be visible in the transaction log we are emitting our defined event.

Initial Release

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/19578.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Ethereum Faucet – 以太坊水龙头区块链毕设代写

提供最优质的资源集合

立即查看 了解详情