Unit 21: You sure can attract a crowd! – 第二十一单元:你一定能吸引一群人!区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Unit 21: You sure can attract a crowd! – 第二十一单元:你一定能吸引一群人!区块链毕设代写 是一篇很好的国外资料

Unit 21: You sure can attract a crowd!

Unit 21: You sure can attract a crowd! - 第二十一单元:你一定能吸引一群人!

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:

Unit 21: You sure can attract a crowd! - 第二十一单元:你一定能吸引一群人!

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).

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单元:你一定能吸引人群!

Unit 21: You sure can attract a crowd! - 第二十一单元:你一定能吸引一群人!

背景

贵公司决定众包其PupperCoin代币,以帮助为网络发展提供资金。这个网络将被用来以分散的方式追踪全球范围内的狗繁殖活动,并允许人类追踪其宠物的遗传轨迹。你已经与必要的法律机构合作过,并且已经为创建一个向公众开放的众包交易开了绿灯。但是,如果众筹成功并达到目标,您需要启用退款,并且您最多只能筹集300以太币。众筹活动将持续24周。

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

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

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

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

创建您的项目

设计合同Minted众筹

使用Remix,创建一个名为木偶角.sol并创建一个标准的ERC20Maintable令牌。既然您已经是这方面的专家了,您可以简单地使用这个入门代码。

创建一个名为puppercoincowdsale.sol像一个标准的众包销售一样准备。

Designing the contracts

ERC20 PupperCoin

您只需使用一个标准的ERC20维护表和ERC20详细合同,硬编码18作为小数参数,而不使用初始供应参数。

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

只需填写木偶角.sol用这个起始代码归档,它包含了你在众包交易中需要处理的完整合同。

PupperCoinCrowdsale

利用众包启动程序代码,将文件保存为众筹.sol.

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

  • 众包销售

  • MintedCrowdsale

  • CappedCrowdsale

  • ReundablePostDeliveryCrowdsale

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

您可以将速率硬编码为1,以保持与乙醚单元(每个乙醚1 TKN,或每wei 1 TKN)相等。如果您想定制您的众包价格,请按照OpenZeppelin文档中的众包价格计算器进行操作。本质上,一个代币(TKN)可以分为TKN,就像乙醚可以分为魏一样。当使用速率为1时,就像10000000000000000wei等于1乙醚一样,10000000000000000TknBits等于1Tkn。

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

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

当超过开放和关闭时间时,请使用“现在”和“现在+24周”从您的PupperCoinCrowdsaleDeployer合同中正确设置时间。你将根据之前建立的模型来部署。利用OpenZeppelin众包销售文档作为部署另一个合同的示例,以及中提供的启动程序代码众筹.sol.

通过从另一个账户(不是筹集资金的同一个账户)向众筹发送以太币来测试众筹交易,然后在确认众筹交易正常运行后,尝试将代币添加到MyCrypto并测试交易。您可以通过用fakenow替换now来测试时间功能,并创建一个setter函数来将fakenow修改为您想要模拟的任何时间。你也可以将关闭时间设置为现在+5分钟,或者任何你想测试的时间线,以缩短众筹时间。

PupperCoinCrowdsaleDeployer

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

Testing the Crowdsale

请记住,可退款PostDeliveryCrowdsale的退款功能只允许在众筹结束并达到目标后进行退款。请参阅OpenZeppelin ReundableCrowdsale文档,了解为什么使用这一逻辑来防止对代币价值的潜在攻击。

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

<Unit 21: You sure can attract a crowd!>

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

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

创建Github repo,然后自述文件.md解释购买PupperCoin的过程的文件(或任何你想到的名字)。确保任何人都可以运行类似的加密步骤。

Deploying the Crowdsale

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

Submission

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

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.

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

www.interchains.cc

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

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Unit 21: You sure can attract a crowd! – 第二十一单元:你一定能吸引一群人!区块链毕设代写

提供最优质的资源集合

立即查看 了解详情