Introduction to Smart Contracts using Solidity – 使用Solidity的智能合约简介区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Introduction to Smart Contracts using Solidity – 使用Solidity的智能合约简介区块链毕设代写 是一篇很好的国外资料

Introduction to Smart Contracts using Solidity

1. Overview

The purpose of this exercise is and introduction to programming smart contracts with Solidity, by building 3 profit splitter contracts. These contracts will do several things:

  • Pay employees quickly and easily (Level 1)
  • Distribute profits to different tiers of employees (Level 2)
  • Distribute company shares for employees in a “deferred equity incentive plan” automatically (Level 3).

The following tools are used to build the Solidity contracts:

  • Ganache – Ganache is a personal blockchain for rapid Ethereum distributed application development.
  • Remix IDE – Remix is a powerful, open source tool that helps you write Solidity contracts straight from the browser
  • Metamask – MetaMask is a Google Chrome extension for the browser which makes it easy for web applications to communicate with the Ethereum blockchain.

2. Level 1: AssociateProfitSplitter Contract

This contract will accept ether into the contract, and divide it evenly among associate-level employees. This will allow the human resources department to pay employees quickly and efficiently.

The following is a summary of steps in the contract:

  • Defined public variables

  • Created a constructor

  • Created 3 functions:
    a. Balance function which returns the contract’s current balance, which should always be ‘0’

    b. Deposit function must ensure only the owner can call the function and that any remainder after division of the deposited amount, needs to be sent back to the owner,

    c. Fallback function which ensures that the logic in the deposit function is executed if ether is sent directly to the contract, which prevents Ether being locked in the contract.

2.1 Images of code and steps performed:

Code in Solidity for AssociateProfitSplitter:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Deploy code in Remix with 0 Ether, for which there is a fee charged to the account:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Test functionality by transfering 45ETH Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Ganache screenshots before and after showing the 15ETH increase in 3 accounts:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-AssociateProfitSplitter Account Value Post-AssociateProfitSplitter

3. Level 2: TieredProfitSplitter Contract

This contract will distribute different percentages of incoming ether to employees at different tiers/levels. For example, the CEO gets paid 60%, CTO 25%, and Bob gets 15%.

The following is a summary of steps modified in the contract:

  • Deposit function: Calculating the points per employee representing a percentage which will be used to calculate the amount to be sent to each employee, with the remainder being sent to the employee with the highest percentage.

3.1 Images of code and steps performed:

Code in Solidity for TieredProfitSplitter:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Compile and deploy code with 0ETH, with fee charged:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Deposit 30ETH, which is allocated as per percentages:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Ganache screenshots before and after showing the 30ETH divided into 3 accounts with starting balance 110.67ETH increasing with 18ETH, 7.5ETH and 4.5ETH respectively:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-TieredProfitSplitter Account Value Post-TieredProfitSplitter

4. Level 3: DeferredEquityPlan Contract

This contract will be managing an employee’s “deferred equity incentive plan,” in which 1000 shares will be distributed over four years to the employee. There is no need to work with ether in this contract, but amounts will be stored that represent the number of distributed shares the employee owns, and enforcing the vetting periods automatically.

The following is a summary of steps modified in the contract:

  • Set human resources in constructor as they will deploy the contract
  • Total shares of 1000 allocated per employee, payable over 4 years, 250 per year
  • Set start_time as Now
  • Create distribute function which distributes shares if a year has passed and ensures maximum of 1000 is allocated over 4 years

4.1 Deploy and test code locally using Fakenow function:

For purposes of testing locally a test file was created, DeferredEquityPlan_test.sol in which a new variable was added ‘fakenow’. Fakenow is used in conjunction with a Fastforward function, that adds 100 days to the contract period. By fastforwarding 4 times, one can then distribute and test the code.

Images of steps performed for testing locally:

Deploy code in local test environment:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Once the code is deployed, you use the “fastforward” function to bypass the test for a payment per year by fast fowarding 4 times. Once that is done, you are able to ‘distribute’ the shares. This is captured in below screenshots with the last one showing the distributed_share of 250 for 1 year.

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

5. Deploy all contracts to live Testnet Kovan:

Kovan testnet was used to deploy contracts to the live testnet. Kovan is a fast and reliable Ethereum Test Chain. Kovan is a Proof of Authority (PoA) publicly accessible blockchain for Ethereum; created and maintained by a consortium of Ethereum developers, to aide the Ethereum developer community.

To deploy to Kovan, we point Metamask to the Kovan network, ensure there is Ether on this network and deploy contracts to the live testnet. Ether was transfered on 2 occations to the account to which the contracts was deployed:

5.1 Transfer 1.8ETH to account where contracts are being deployed, the confirmation and transaction:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

5.2 Images of AssociateProfitSplitter deployed in Kovan:

  1. Contract Deployment:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  2. Deposit of 1ETH, split equally between 3 accounts:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  3. Balances before and after deposit of 1ETH in AssociateProfitSplitter contract – images taken from MyCrypto in Kovan environment:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-AssociateProfitSplitter Account Value Post-AssociateProfitSplitter

5.3 Images of TieredProfitSplitter deployed in Kovan:

  1. Contract Deployment:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  2. Deposit 1ETH, which is divided porpotionally into 3 accounts:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  3. Balances before and after deposit of 1ETH:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-TieredProfitSplitter Account Value Post-TieredProfitSplitter

5.4 Images of DeferredEquityPlan deployed in Kovan testnet:

  1. Contract Deployment:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  2. Distrubute shares with 0ETH value: In live test environment we did not use the Fakenow function, thus the distribution failed due to the fact that 1 year has not passed.

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

5.6 Accounts used for Kovan testnet:

Account where varius contracts are deployed: 0xAC814448D563B290C8A40c4c076307A034cC17b9

Accounts used on Kovan testnet to deposit employee equity (AssociateProfitSplitter and TieredProfitSplitter):

  • Employee1 – 0x81080EB0235f9B0CB20ECf562e9b674d323E64D3
  • Employee2 – 0xa208A69C53c1CFdDb514e0bAa5D44eF5E473653F
  • Employee3 – 0x1AD1a5a270D5870a5D66720be00DDE26D6Bc4994

6. File Location:

Starter code: Level 1 Associate Profit Splitter: APS_starter_code

Level 2 Tiered Profit Splitter: TPS_starter_code

Level 3 Deferred Equity Plan Test Local: DPStest_starter_code

Level 4 Deferred Equity Plan Kovan Testnet: DPSKovan_starter_code

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.

Final version of Readme


使用Solidity的智能合约简介

1。概述

本练习的目的是通过构建3个利润分割契约,并介绍如何用Solidity编程智能合约。这些合同将做几件事:

  • 快速轻松地向员工支付薪酬(第1级)
  • 将利润分配给不同级别的员工(第2级)
  • 在“递延股权激励计划”中为员工自动分配公司股票(第3级)。

以下工具用于构建稳固性合同:

  • Ganache是用于快速以太坊eth分布式应用程序开发的个人区块链blockchain。这是一个强大的浏览器界面,它可以帮助你轻松地用Chrome浏览器界面来进行交流。
  • 定义的公共变量
  • 创建了一个构造函数

2。1级:AssociateProfitSplitter合同

此合同将接受以太合同,并在副级员工之间平均分配。这将使人力资源部能够迅速有效地支付员工工资。

以下是契约中步骤的摘要:

  • 创建了3个函数:
    a.返回合同当前余额的Balance函数,该函数应始终为“0”
    b。Deposit函数必须确保只有所有者可以调用该函数,并且在对存款金额进行除法后的任何余数都需要回传给所有者,
    c.回退功能,确保在ether直接发送到合同时执行deposit函数中的逻辑,从而防止ether被锁定在合同中。
  • 存款功能:计算每个员工的积分,代表一个百分比,该百分比将用于计算发送给每个员工的金额,剩余部分将发送给比例最高的员工。
  • 在建设者中设置人力资源部,因为他们将部署合同

2.1执行的代码和步骤的图像:

AssociateProfitSplitter的可靠代码:

<Introduction to Smart Contracts using Solidity>

将代码与0乙醚混合部署,为此,向账户收取费用:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

通过转移45ETH<Introduction to Smart Contracts using Solidity>

Ganache屏幕截图测试功能,显示3个账户中15以太的增长:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
账户 Account Value Post-AssociateProfitSplitter

3。2级:分层ProfitSplitter合同

本合同将向不同的员工分配不同百分比的乙醚层次/层次。例如,首席执行官的薪酬为60%,首席技术官的薪酬为25%,鲍勃的薪酬为15%。

以下是合同中修改步骤的摘要:

  • 为每位员工分配1000份总股份,4年内支付,每年250份

3.1执行的代码和步骤的图像:

TieredProfitPlitter的可靠代码:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

使用0ETH编译和部署代码,并收取费用:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Deposit 30ETH,按百分比分配:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Ganache屏幕截图,显示30ETH分成3个账户,期初余额110.67ETH分别以18ETH、7.5ETH和4.5ETH递增:

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-TieredProfitSplitter Account Value Post-TieredProfitSplitter

4。第3级:延迟公平计划合同

本合同将管理员工的“递延股权激励计划”,“其中1000股将在4年内分配给员工。在这个合同中没有必要使用ether,但是存储的金额将代表员工所拥有的已分配股份的数量,并自动执行审核周期。

以下是合同中修改的步骤的摘要:

  • 将开始时间设置为现在
  • 创建分配股份的分配功能如果一年过去了,并确保在4年内最多分配1000张合同部署:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
  • 第1笔存款,在3个账户中平均分配:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
  • 在AssociateProfitPlitter合同中存入第1位前后的余额-图片来源Kovan环境中的MyCrypto:

4.1使用Fakenow函数在本地部署和测试代码:

为了进行本地测试,创建了一个测试文件,DeferredEquityPlan_测试.sol其中添加了一个新变量“fakenow”。Fakenow与Fastforward功能结合使用,可将合同期限延长100天。通过快速转发4次,可以分发和测试代码。

本地测试所执行步骤的图像:

在本地测试环境中部署代码:

<Introduction to Smart Contracts using Solidity>

一旦部署了代码,您就可以使用“fastforward”功能通过快速转发4次来绕过每年支付测试。一旦完成,你就可以“分配”股票了。下面的截图显示了一年内分配的250个帴u份额。

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

5。将所有合同部署到live Testnet Kovan:

Kovan testnet was used to deploy contracts to the live testnet. Kovan is a fast and reliable Ethereum Test Chain. Kovan is a Proof of Authority (PoA) publicly accessible blockchain for Ethereum; created and maintained by a consortium of Ethereum developers, to aide the Ethereum developer community.

<Introduction to Smart Contracts using Solidity>

5.1将1.8ETH传输到部署合同的帐户,确认和事务处理:

Kovan testnet用于将合同部署到实时测试网。Kovan是一个快速可靠的以太坊eth测试链。Kovan是以太坊eth的权威证明(PoA)可公开访问的区块链blockchain;由以太坊eth开发者联盟创建和维护,以帮助以太坊eth开发者社区。

5.2部署在Kovan的AssociateProfitSplitter映像:

  1. 合同部署:
    <Introduction to Smart Contracts using Solidity>
  2. Deposit 1ETH,分为3个账户:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
  3. 第1期存款前后余额:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-AssociateProfitSplitter Account Value Post-AssociateProfitSplitter

5.3部署在Kovan的TieredProfitPlitter映像:

  1. 合同部署:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  2. 合同部署:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
  3. 分配具有0位值的股份:在现场测试环境中,我们没有使用Fakenow函数,因此由于一年没过去的事实。
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介 Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介
Account Value Pre-TieredProfitSplitter Account Value Post-TieredProfitSplitter

5.4部署在Kovan testnet:

  1. 合同部署:
    Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  2. Employee1-0x81080EB0235F9B0CB20ECFF56E9B674D323E64D3D34D33

第1个月存款前后余额:

5.6用于Kovan testnet的帐户:

Account where varius contracts are deployed: 0xAC814448D563B290C8A40c4c076307A034cC17b9

合同部署:
Introduction to Smart Contracts using Solidity - 使用Solidity的智能合约简介

  • 李>Employee2-0xA208A69C53CC53C1CFDDB514E0Baa5D44EF5E44EE44E44E44E44E4765353F
  • 李><李>雇员3-0x1AD1A5A270D570A5D6720Be00DD26262620Be00D26B262626262620被继继D642929292929292929292929292994
  • 账户价值预AssociateProfiitSplitplitplitplitplitplitplitpl> 账户

6。文件位置:

分配具有0位值的股份:在现场测试环境中,我们没有使用Fakenow函数,由于一年未过,分配失败。

Level 2 Tiered Profit Splitter: TPS_starter_code

<Introduction to Smart Contracts using Solidity>

部署varius合同的账户:0xAC814448D563B290C8A40c4c076307A034cC17b9

在Kovan testnet上用于存放员工权益的账户(AssociateProfitSplitter和TieredProfitSplitter):

Final version of Readme

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

www.interchains.cc

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

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Introduction to Smart Contracts using Solidity – 使用Solidity的智能合约简介区块链毕设代写

提供最优质的资源集合

立即查看 了解详情