Unit 20 – “Looks like we’ve made our First Contract!” – 第20单元-“看来我们签了第一份合同!”区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Unit 20 – “Looks like we’ve made our First Contract!” – 第20单元-“看来我们签了第一份合同!”区块链毕设代写 是一篇很好的国外资料

Unit 20 – “Looks like we’ve made our First Contract!”

Unit 20 -

Background

Your new startup has created its own Ethereum-compatible blockchain to help connect financial institutions, and the team wants to build smart contracts to automate some company finances to make everyone’s lives easier, increase transparency, and to make accounting and auditing practically automatic!

Fortunately, you’ve been learning how to program smart contracts with Solidity! What you will be doing this assignment is creating 3 ProfitSplitter contracts. These contracts will do several things:

  • Pay your Associate-level employees quickly and easily.

  • Distribute profits to different tiers of employees.

  • Distribute company shares for employees in a “deferred equity incentive plan” automatically.

Files

  • AssociateProfitSplitter.sol — Level 1 starter code.

Instructions

This assignment has three levels of difficulty, with each contract increasing in complexity and capability. Although it is highly recommended you complete all three contracts, you are only required to solve one of the three contracts. Recommended to start with Level 1, then move forward as you complete the challenges. You can build all three with the skills you already have!

  • Level One is an AssociateProfitSplitter contract. This will accept Ether into the contract and divide the Ether evenly among the associate level employees. This will allow the Human Resources department to pay employees quickly and efficiently.

Starting your project

Navigate to the Remix IDE and create a new contract called AssociateProfitSplitter.sol using the starter code for level one above.

While developing and testing your contract, use the Ganache development chain, and point MetaMask to localhost:8545, or replace the port with what you have set in your workspace.

Level One: The AssociateProfitSplitter Contract

At the top of your contract, you will need to define the following public variables:

  • employee_one — The address of the first employee. Make sure to set this to payable.

  • employee_two — Another address payable that represents the second employee.

  • employee_three — The third address payable that represents the third employee.

Create a constructor function that accepts:

  • address payable _one

  • address payable _two

  • address payable _three

Within the constructor, set the employee addresses to equal the parameter values. This will allow you to avoid hardcoding the employee addresses.

Next, create the following functions:

  • balance — This function should be set to public view returns(uint), and must return the contract’s current balance. Since we should always be sending Ether to the beneficiaries, this function should always return 0. If it does not, the deposit function is not handling the remainders properly and should be fixed. This will serve as a test function of sorts.

  • deposit — This function should set to public payable check, ensuring that only the owner can call the function.

    • In this function, perform the following steps:

      • Set a uint amount to equal msg.value / 3; in order to calculate the split value of the Ether.

      • Transfer the amount to employee_one.

      • Repeat the steps for employee_two and employee_three.

      • Since uint only contains positive whole numbers, and Solidity does not fully support float/decimals, we must deal with a potential remainder at the end of this function since amount will discard the remainder during division.

      • We may either have 1 or 2 wei leftover, so transfer the msg.value - amount * 3 back to msg.sender. This will re-multiply the amount by 3, then subtract it from the msg.value to account for any leftover wei, and send it back to Human Resources.

  • Create a fallback function using function() external payable, and call the deposit function from within it. This will ensure that the logic in deposit executes if Ether is sent directly to the contract. This is important to prevent Ether from being locked in the contract since we don’t have a withdraw function in this use-case.

Test the contract

In the Deploy tab in Remix, deploy the contract to your local Ganache chain by connecting to Injected Web3 and ensuring MetaMask is pointed to localhost:8545.

You will need to fill in the constructor parameters with your designated employee addresses.

Test the deposit function by sending various values. Keep an eye on the employee balances as you send different amounts of Ether to the contract and ensure the logic is executing properly.

Unit 20 -

Deploy the contracts to a live Testnet

Once you feel comfortable with your contracts, point MetaMask to the Kovan or Ropsten network. Ensure you have test Ether on this network!

After switching MetaMask to Kovan, deploy the contracts as before and copy/keep a note of their deployed addresses. The transactions will also be in your MetaMask history, and on the blockchain permanently to explore later.

Unit 20 -

Resources

Building the next financial revolution isn’t easy, but we need your help, don’t be intimidated by the semicolons!

There are lots of great resources to learn Solidity. Remember, you are helping push the very edge of this space forward, so don’t feel discouraged if you get stuck! In fact, you should be proud that you are taking on such a challenge!

For some succinct and straightforward code snips, check out Solidity By Example

For a more extensive list of awesome Solidity resources, checkout Awesome Solidity

Another tutorial is available at EthereumDev.io

If you enjoy building games, here’s an excellent tutorial called CryptoZombies

Submission

Create a README.md that explains how each of the contracts work and what the motivation for each of the contracts is. Also, please provide screenshots to illustrate the functionality (e.g. how you send transactions, how the transferred amount is then distributed by each of the contracts, and how the timelock functionality can be tested with the fastforward function). Alternatively, you can also record your interactions with the contract as a gif (e.g. https://www.screentogif.com/)

Upload the README.md to a Github repository and provide the testnet address for others to interact with the contract.

upload


第20单元-“看来我们签了第一份合同!”

Unit 20 -

背景

您的新创业公司已经创建了自己的以太坊eth兼容区块链blockchain,以帮助连接金融机构,团队希望构建智能合约,使一些公司财务自动化,以使每个人的生活更轻松,增加透明度,并使会计和审计实际上自动化!

幸运的是,您已经学习了如何使用Solidity编程智能合约!你要做的是创建3个ProfitSplitter合同。这些合同可以做几件事:

  • 快速支付您的助理级别员工很容易。
  • 将利润分配给不同层次的员工。
  • 在“递延股权激励计划”中自动为员工分配公司股份。

文件

  • 屁股ociateProfitSplitter.sol文件–一级起动代码。

说明

这项任务有三个难度等级,每个合同的复杂性和能力都在增加。尽管强烈建议您完成所有三份合同,但您只需解决三份合同中的一份。建议从1级开始,然后在完成挑战后继续前进。你可以建立所有这三个与技能,你已经有了!

  • 一级是AssociateProfitSpliter合同。这将把乙醚纳入合同,并将乙醚平均分配给员工。这将使人力资源部能够快速有效地向员工支付薪酬。

启动项目

导航到RemixIDE并创建一个名为Ass的新契约ociateProfitSplitter.sol文件使用一级以上的起始代码。

在开发和测试合同时,使用Ganache开发链,并将MetaMask指向本地主机:8545,或将端口替换为工作区中设置的端口。

级别一:AssociateProfitSpliter合同

在合同顶部,您需要定义以下公共变量:

  • 雇员一——第一个雇员的地址。确保将此设置为“应付”。
  • employeeu two—另一个代表第二个雇员的应付地址。
  • employeeu three—代表第三名员工的第三个应付地址。

创建一个构造函数,该构造函数接受:

  • 应付地址u one
  • 应付地址u two
  • 应付地址u three

在构造函数中,将雇员地址设置为等于参数值。这将允许您避免硬编码员工地址。

接下来,创建以下函数:

  • 余额–此函数应设置为公共视图返回(uint),并且必须返回合同的当前余额。因为我们应该总是向受益人发送乙醚,所以这个函数应该总是返回0。如果没有,存款功能将无法正确处理剩余部分,应予以修复。这将作为某种测试函数。
  • 存款–此函数应设置为公共应付支票,确保只有所有者可以调用此函数。在此函数中,执行以下步骤:将uint amount设置为等于消息值/3;以计算乙醚的分流值。将金额转移到员工账户。对employeeu two和employeeu three重复上述步骤。由于uint只包含正整数,而Solidity不完全支持浮点数/小数,因此我们必须在函数末尾处理一个可能的余数,因为amount在除法过程中将丢弃余数。我们可能有1或2个卫剩余,所以转移消息值-金额*3返回邮件发件人. 这将把数量再乘以3,然后从消息值把剩下的小薇算上帐,并送回人力资源部。
  • 使用function()external payable创建一个回退函数,并在其中调用deposit函数。这将确保如果以太直接发送到合同,那么存放的逻辑将执行。这是很重要的

测试合同

在Remix的Deploy选项卡中,通过连接到Injected Web3并确保指向MetaMask,将契约部署到本地Ganache链本地主机:8545。

您需要用指定的员工地址填写构造函数参数。

通过发送各种值来测试存款功能。在向合同发送不同数量的乙醚时,注意员工余额,确保逻辑正确执行。

Unit 20 -

将合同部署到实时测试网

一旦您对合同感到满意,请将MetaMask指向Kovan或Ropsten网络。确保此网络上有测试以太网!

将MetaMask切换到Kovan后,像以前一样部署契约,并复制/记录它们部署的地址。这些交易也将出现在你的元掩码历史中,并永久性地出现在区块链blockchain上,以供以后探索。构建下一次金融革命并不容易,但我们需要您的帮助,不要被分号吓倒!

学习稳固性有很多好的资源。请记住,你正在帮助推动这个空间的边缘向前,所以不要感到气馁,如果你被卡住了!事实上,你应该为自己能接受这样的挑战而感到骄傲!

资源

对于一些简洁明了的代码片段,请通过示例查看Solidity

对于更广泛的awesome Solidity资源列表,请查看awesome Solidity

另一个教程可在以太网设备io

如果您喜欢构建游戏,这里有一个名为CryptoZombies的优秀教程

创建一个自述文件.md这就解释了每个契约是如何工作的,以及每个契约的动机是什么。另外,请提供屏幕截图来说明功能(例如,您如何发送交易,然后每个合同如何分配转账金额,以及如何使用fastforward功能测试timelock功能)。或者,您也可以将与合同的交互记录为gif(例如。https://www.screentogif.com/)

上传自述文件.md并为其他人提供testnet地址以与契约交互。

提交

Create a README.md that explains how each of the contracts work and what the motivation for each of the contracts is. Also, please provide screenshots to illustrate the functionality (e.g. how you send transactions, how the transferred amount is then distributed by each of the contracts, and how the timelock functionality can be tested with the fastforward function). Alternatively, you can also record your interactions with the contract as a gif (e.g. https://www.screentogif.com/)

Upload the README.md to a Github repository and provide the testnet address for others to interact with the contract.

upload

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

www.interchains.cc

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

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Unit 20 – “Looks like we’ve made our First Contract!” – 第20单元-“看来我们签了第一份合同!”区块链毕设代写

提供最优质的资源集合

立即查看 了解详情