hw21-advanced-solidity – hw21高级坚固性区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,hw21-advanced-solidity – hw21高级坚固性区块链毕设代写 是一篇很好的国外资料

hw21-advanced-solidity

Unit 21: You sure can attract a crowd!

hw21-advanced-solidity - hw21高级坚固性

Background

Your company has decided to crowdsale their PupperCoin token in order to help fund the network development. This network will be used to track the dog breeding activity across the globe in a decentralized way, and allow humans to track the genetic trail of their pets. You have already worked with the necessary legal bodies and have the green light on creating a crowdsale open to the public. However, you are required to enable refunds if the crowdsale is successful and the goal is met, and you are only allowed to raise a maximum of 300 Ether. The crowdsale will run for 24 weeks.

You will need to create an ERC20 token that will be minted through a Crowdsale contract that you can leverage from the OpenZeppelin Solidity library.

This crowdsale contract will manage the entire process, allowing users to send ETH and get back PUP (PupperCoin). This contract will mint the tokens automatically and distribute them to buyers in one transaction.

It will need to inherit Crowdsale, CappedCrowdsale, TimedCrowdsale, RefundableCrowdsale, and MintedCrowdsale.

You will conduct the crowdsale on the Kovan or Ropsten testnet in order to get a real-world pre-production test in.

Instructions

Creating your project

Using Remix, create a file called PupperCoin.sol and create a standard ERC20Mintable token. Since you’re already an expert at this, you can simply use this starter code.

Create a new contract named PupperCoinCrowdsale.sol, and prepare it like a standard crowdsale.

Designing the contracts

ERC20 PupperCoin

You will need to simply use a standard ERC20Mintable and ERC20Detailed contract, hardcoding 18 as the decimals parameter, and leaving the initial_supply parameter alone.

You don’t need to hardcode the decimals, however since most use-cases match Ethereum’s default, you may do so.

Simply fill in the PupperCoin.sol file with this starter code, which contains the complete contract you’ll need to work with in the Crowdsale.

PupperCoinCrowdsale

Leverage the Crowdsale starter code, saving the file in Remix as Crowdsale.sol.

You will need to bootstrap the contract by inheriting the following OpenZeppelin contracts:

  • Crowdsale

  • MintedCrowdsale

  • CappedCrowdsale

  • TimedCrowdsale

  • RefundablePostDeliveryCrowdsale

You will need to provide parameters for all of the features of your crowdsale, such as the name, symbol, wallet for fundraising, goal, etc. Feel free to configure these parameters to your liking.

You can hardcode a rate of 1, to maintain parity with Ether units (1 TKN per Ether, or 1 TKNbit per wei). If you’d like to customize your crowdsale rate, follow the Crowdsale Rate calculator on OpenZeppelin’s documentation. Essentially, a token (TKN) can be divided into TKNbits just like Ether can be divided into wei. When using a rate of 1, just like 1000000000000000000 wei is equal to 1 Ether, 1000000000000000000 TKNbits is equal to 1 TKN.

Since RefundablePostDeliveryCrowdsale inherits the RefundableCrowdsale contract, which requires a goal parameter, you must call the RefundableCrowdsale constructor from your PupperCoinCrowdsale constructor as well as the others. RefundablePostDeliveryCrowdsale does not have its own constructor, so just use the RefundableCrowdsale constructor that it inherits.

If you forget to call the RefundableCrowdsale constructor, the RefundablePostDeliveryCrowdsale will fail since it relies on it (it inherits from RefundableCrowdsale), and does not have its own constructor.

When passing the open and close times, use now and now + 24 weeks to set the times properly from your PupperCoinCrowdsaleDeployer contract.

PupperCoinCrowdsaleDeployer

In this contract, you will model the deployment based off of the ArcadeTokenCrowdsaleDeployer you built previously. Leverage the OpenZeppelin Crowdsale Documentation for an example of a contract deploying another, as well as the starter code provided in Crowdsale.sol.

Testing the Crowdsale

Test the crowdsale by sending Ether to the crowdsale from a different account (not the same account that is raising funds), then once you confirm that the crowdsale works as expected, try to add the token to MyCrypto and test a transaction. You can test the time functionality by replacing now with fakenow, and creating a setter function to modify fakenow to whatever time you want to simulate. You can also set the close time to be now + 5 minutes, or whatever timeline you’d like to test for a shorter crowdsale.

When sending Ether to the contract, make sure you hit your goal that you set, and finalize the sale using the Crowdsale‘s finalize function. In order to finalize, isOpen must return false (isOpen comes from TimedCrowdsale which checks to see if the close time has passed yet). Since the goal is 300 Ether, you may need to send from multiple accounts. If you run out of prefunded accounts in Ganache, you can create a new workspace.

Remember, the refund feature of RefundablePostDeliveryCrowdsale only allows for refunds once the crowdsale is closed and the goal is met. See the OpenZeppelin RefundableCrowdsale documentation for details as to why this is logic is used to prevent potential attacks on your token’s value.

You can add custom tokens in MyCrypto from the Add custom token feature:

hw21-advanced-solidity - hw21高级坚固性

You can also do the same for MetaMask. Make sure to purchase higher amounts of tokens in order to see the denomination appear in your wallets as more than a few wei worth.

Deploying the Crowdsale

Deploy the crowdsale to the Kovan or Ropsten testnet, and store the deployed address for later. Switch MetaMask to your desired network, and use the Deploy tab in Remix to deploy your contracts. Take note of the total gas cost, and compare it to how costly it would be in reality. Since you are deploying to a network that you don’t have control over, faucets will not likely give out 300 test Ether. You can simply reduce the goal when deploying to a testnet to an amount much smaller, like 10,000 wei.

Submission

Create a Github repo, and a README.md file explaining the process for purchasing PupperCoin (or whatever name you came up with).

Also, please provide screenshots to illustrate the functionality (e.g. how you send Ether to the contract, how you add the token to MyCrypto and test a transaction, and how you test the time functionality etc.). Alternatively, you can also record your interactions with the contract as a gif (e.g. https://www.screentogif.com/)

Ensure that anyone can run the steps and add the token to MyCrypto, or a similar wallet.

Include information such as the token parameters, token name, crowdsale cap, etc.


第21单元:你肯定能吸引人群!

背景

贵公司已决定众售他们的PupperCoin代币,以资助网络发展。这个网络将被用来以分散的方式追踪全球的养狗活动,并允许人类追踪宠物的基因轨迹。你已经与必要的法律机构合作,并为创建面向公众的众售开了绿灯。但是,如果众筹成功并且达到了目标,您需要启用退款,并且您最多只能筹集300英镑。众筹将持续24周。

说明

您需要创建一个ERC20代币,该代币将通过众售合同铸造,您可以利用OpenZeppelin Solidity库。

这个众包合同将管理整个过程,允许用户发送ETH并取回PUP(PupperCoin)。此合同将自动铸造代币,并在一次交易中将其分配给买家。

它将需要继承Crowdsale、CappedCrowdsale、TimedCrowdsale、ReturnableCrowdSale和MintedCrowdsale。

您将在Kovan或Ropsten testnet上进行众售,以便在中获得真实的预生产测试。

使用混音,创建一个名为木偶胶.sol并创建一个标准的可维护令牌。既然您已经是这方面的专家,您可以简单地使用这个启动代码。

创建项目

设计合同

创建一个名为puppercoin众售.sol,像标准的众筹一样准备。

您只需使用标准的ERC20Mintable和ERC20Detailed合同,硬编码18作为小数参数,而不使用初始的u supply参数。

PupperCoinCrowdsaleDeployer

您不需要硬编码小数,但是由于大多数用例都匹配以太坊eth的默认值,因此您可以这样做。

只需填写木偶胶.sol文件与此启动代码,其中包含了完整的合同,你将需要在众包工作。

利用众售启动程序代码,将文件保存在Remix中作为众售.sol.

测试众售

您需要通过继承以下OpenZeppelin合同来引导合同:

众售

  • 众售
  • 封顶众售
  • TimedCrowdsale
  • 可退款发货后众售
  • 您需要为众售的所有功能提供参数,例如名称,符号,钱包筹款,目标等,请随意配置这些参数,你喜欢的。

您可以将速率硬编码为1,以保持与乙醚单位的奇偶性(每乙醚1 TKN或每魏1 TKNbit)。如果您想定制您的众售率,请遵循OpenZeppelin文档中的众售率计算器。从本质上讲,一个代币(TKN)可以分为tknbit,就像以太可以分为wei一样。当使用1的速率时,就像10000000000000000 wei等于1乙醚一样,10000000000000000 TKNbits等于1 TKN。

由于ReturnablePostDeliveryCrowdsale继承了ReturnableCrowdsale合同,该合同需要一个目标参数,因此您必须从PupperCoinCrowdsale构造函数以及其他构造函数中调用ReturnableCrowdsale构造函数。ReturnablePostDeliveryCrowdsale没有自己的构造函数,所以只需使用它继承的ReturnableCrowdsale构造函数即可。

如果忘记调用RefundableCrowdsale构造函数,RefundablePostDeliveryCrowdsale将失败,因为它依赖于它(它从RefundableCrowdsale继承),并且没有自己的构造函数。

通过打开和关闭时间时,使用now和now+24周从您的PupperCoinCrowdsaleDeployer合同中正确设置时间。

在本合同中,您将基于先前构建的ArcadeTokenCrowdsaleDeployer对部署进行建模。利用OpenZeppelin众售文档作为部署另一个合同的示例,以及中提供的启动程序代码众售.sol.

部署众售

通过从不同的帐户(不是筹集资金的同一个帐户)向众售发送以太来测试众售,然后在确认众售按预期工作后,尝试将令牌添加到MyCrypto并测试交易。您可以通过将now替换为fakenow来测试时间功能,并创建setter函数来将fakenow修改为您想要模拟的任何时间。您还可以将关闭时间设置为现在+5分钟,或者任何您想测试的时间线,以便缩短众筹时间。

Testing the Crowdsale

将以太发送到合同时,确保达到设定的目标,并使用Crowdsale的finalize功能完成销售。为了完成,isOpen必须返回false(isOpen来自TimedCrowdsale,它检查关闭时间是否已经过去)。由于目标是300以太,您可能需要从多个帐户发送。如果您在Ganache中用完了预先准备好的帐户,您可以创建一个新的工作区。

请记住,ReturnablePostDeliveryCrowdsale的退款功能只允许在众售结束并达到目标后退款。请参阅OpenZeppelin returnablecrowdsale文档以了解有关为什么使用此逻辑来防止对令牌价值的潜在攻击的详细信息。

您可以通过添加自定义令牌功能在MyCrypto中添加自定义令牌:

hw21-advanced-solidity - hw21高级坚固性

您也可以对MetaMask执行相同的操作。一定要购买更高数额的代币,以便看到面额出现在您的钱包超过几个魏价值。

将众售部署到Kovan或Ropsten测试网,并存储部署的地址以备将来使用。将MetaMask切换到所需的网络,并使用Remix中的Deploy选项卡来部署契约。注意总的天然气成本,并将其与实际成本进行比较。由于您正在部署到一个您无法控制的网络上,水龙头不太可能发出300测试信号。您可以简单地将部署到testnet时的目标减少到更小的数量,比如10000个。

Deploying the Crowdsale

创建一个Github repo自述文件.md说明购买PupperCoin(或任何你想到的名字)过程的文件。

Submission

另外,请提供屏幕截图来说明功能(例如,如何向合同发送以太,如何将令牌添加到MyCrypto并测试事务,以及如何测试时间功能等)。或者,您也可以将与合同的交互记录为gif(例如。https://www.screentogif.com/)

确保任何人都可以运行这些步骤并将令牌添加到MyCrypto或类似的钱包中。

包括诸如代币参数、代币名称、众售上限等信息。

Include information such as the token parameters, token name, crowdsale cap, etc.

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

www.interchains.cc

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

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

提供最优质的资源集合

立即查看 了解详情