Advanced-Solidity-Crowdsale – 先进可靠众筹区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Advanced-Solidity-Crowdsale – 先进可靠众筹区块链毕设代写 是一篇很好的国外资料

Advanced-Solidity-Crowdsale

In this project, we will create a crowdsale PupperCoin token to fund a network development. The goal of this crowdsale is to raise 300 Ether, so we will enable refund if the crowdsale is successfull and the goal is met within 24 weeks. We will leverage the OpenZeppelin Solidity library to create an ERC20 token that will be minted through the Crowdsale contract which will manage the entire process, allowing users to send Ether and get back PupperCoin (PUP).

Creating the project

We will use Remix to create two files, one for a standard ERC20Mintable token and a second for a standard crowdsale, PupperCoinCrowdsale.

Designing the contracts

ERC20 PupperCoin

For this contract, we will use a standard ERC20Mintable and ERC20Detailed contract and hardcode 18 as the decimals parameter but we will leave the initial_supply parameter alone for now.

contract PupperCoin is ERC20, ERC20Detailed, ERC20Mintable {

constructor(      string memory name,     string memory symbol,     uint initial_supply      )      ERC20Detailed(name, symbol, 18)     public      {     // constructor can stay empty } 

}

PupperCoinCrowdsale

We will leverage a standard crowdasle and bootstrap that contract to inherit the following OpenZeppelin contracts:

Crowdsale MintedCrowdsale CappedCrowdsale TimedCrowdsale RefundablePostDeliveryCrowdsale

We provided parameters for all of the features of our crowdsale, such as the name, symbol, wallet for fundraising, goal, cap, openingtime and closingtime. We hardcoded a rate of 1, to maintain parity with Ether units (1 TKN per Ether, or 1 TKNbit per wei). Since PupperCoinCrowdsale inherited all the above contracts, we called them into the constructor. We passed the open and close times, to now and now + 24 weeks to set the times properly from our PupperCoinCrowdsaleDeployer contract.

PupperCoinCrowdsaleContract:

contract PupperCoinSale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, RefundablePostDeliveryCrowdsale {

constructor(      uint rate, //  rate in 1 TKN per Ether, or 1 TKNbit per wei)     address payable wallet, // sale beneficiary     PupperCoin token, // the PupperCoin itself that the PupperCoinSale will work with     uint cap, // Total cap in Ether     uint goal, //minimum goal in Ether     uint open, //Opening time     uint close //Closing time       )     MintedCrowdsale()     CappedCrowdsale(cap)     TimedCrowdsale(open, close)     RefundableCrowdsale(goal)     Crowdsale(rate, wallet, token)     public 

PupperCoinCrowdSaleDeployer

Now, below PupperCoinSale, at the top of the PupperCoinSaleDeployer contract, we added the following variables to store the addresses of the PupperCoin and PupperCoinSale contracts that this contract will be deploying:

An address public called token_sale_address, which will store PupperCoinSale’s address once deployed.

An address public called token_address, which will store PupperCoin’s address once deployed.

Inside of the constructor,

We created the PupperCoin token by defining a variable like PupperCoin token and setting it to equal new PupperCoin (). Inside of the parameters of new PupperCoin, we passed in the name and symbol variables. For the initial_supply variable that PupperCoin expects, we passed in 0.

For example:

PupperCoin token = new PupperCoin(name, symbol, 0); 

Then, we stored the address of the token by using token_address = address(token).

Next, we created the PupperCoinSale contract instance using the same logic we used when creating PupperCoin token. We stored the variable in PupperCoinSale puppercoinSale and set the parameters:

rate, hard-coded to 1 in order to maintain the same units as Ether.

wallet, passed in from the main constructor, this is the wallet that will get paid all Ether raised by the PupperCoinSale.

token, the actual token variable where PupperCoin is stored.

cap, the total cap in Ether.

goal, the 300 Ether target goal.

open, opening time of the crowdsale.

close, closing time of the crowdsale.

Once again, we stored the address of the PupperCoinSale in the token_sale_address variable for easy access later.

Finally, we set the PupperCoinSale contract as a minter, then renounce “mintership” from the PupperCoinSaleDeployer contract, like so:

token.addMinter(token_sale_address);

token.renounceMinter();

We need to do this because when we set our token as ERC20Mintable, the msg.sender is automatically set as the default minter. Since PupperCoinSaleDeployer is actually msg.sender in this case, this step will ensure that the PupperCoinSale is the actual minter, as expected.

contract PupperCoinSaleDeployer {

address public token_sale_address; address public token_address;  constructor(     string memory name,     string memory symbol,     address payable wallet, // this address will receive all Ether raised by the sale     uint cap, // Total cap in Ether     uint goal // The minimum goal in Ether  )      public       {     // create the PupperCoin and keep its address handy     PupperCoin token = new PupperCoin(name, symbol, 0);     token_address = address(token);      // create the PupperCoinSale and tell it about the token, set the goal, and set the open and close times to now and now + 24 weeks,     PupperCoinSale puppercoinSale = new PupperCoinSale(1, wallet, token, cap, goal, now, now + 24 weeks);     token_sale_address = address(puppercoinSale);      // make the PupperCoinSale contract a minter, then have the PupperCoinSaleDeployer renounce its minter role     token.addMinter(token_sale_address);     token.renounceMinter(); } 

}

Testing the Crowdsale

To send Ether and get PUP back you will need to use the deployed contract’s approve function, you enter your address and the amount you are spending and confirm the transaction on MetaMask to complete the transaction (see screenshot).

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

Update README.md


高级实用型众包

在这个项目中,我们将创建一个众筹PupperCoin代币来资助网络开发。本次众筹的目标是筹集300乙醚,因此,如果众筹成功并在24周内达到目标,我们将提供退款。我们将利用OpenZeppelin Solidity库创建一个ERC20代币,该代币将通过众包销售合同进行铸造,该代币将管理整个流程,允许用户发送以太币并取回PupperCoin(PUP)。

创建项目

我们将使用Remix创建两个文件,一个用于标准ERC20维护令牌,另一个用于标准众包销售,即PupperCoinCrowdsale。

设计合同饼干

ERC20 PupperCoin

对于本合同,我们将使用标准ERC20维护表和ERC20详细合同以及硬编码18作为小数参数,但我们暂时不使用初始供应参数。

合同编号为ERC20,详细说明为ERC20,ERC20维护{/p>

constructor(      string memory name,     string memory symbol,     uint initial_supply      )      ERC20Detailed(name, symbol, 18)     public      {     // constructor can stay empty } 

}

PupperCoinCrowdsale

我们将利用一个标准的crowdasle和bootstrap来继承以下OpenZeppelin合同:

众包销售MintedCrowdsale CappedCrowdsale TimedCrowdsale returnablepostdeliverycrowdsale

我们为众包的所有功能提供了参数,例如名称,符号、筹款钱包、目标、上限、开放时间和结束时间。我们将速率硬编码为1,以保持与乙醚单位的相等(每个乙醚1 TKN,或每wei 1 TKN)。由于PuppercocineCrowdsale继承了上述所有合同,我们将它们调用到构造函数中。我们通过了开放和关闭时间,到现在和现在+24周,从我们的傀儡CrowdsaleDeployer合同正确设置时间。

puppercoinsallowdsale合同:

PupperCoinSale是指众包、MintedCrowdsale、CappedCrowdsale、TimedCrowdsale、可退款的postdeliverycrowdsale{/p>

constructor(      uint rate, //  rate in 1 TKN per Ether, or 1 TKNbit per wei)     address payable wallet, // sale beneficiary     PupperCoin token, // the PupperCoin itself that the PupperCoinSale will work with     uint cap, // Total cap in Ether     uint goal, //minimum goal in Ether     uint open, //Opening time     uint close //Closing time       )     MintedCrowdsale()     CappedCrowdsale(cap)     TimedCrowdsale(open, close)     RefundableCrowdsale(goal)     Crowdsale(rate, wallet, token)     public 

PupperCoinCrowdSaleDeployer

现在,在PupperCoinSale下面,puppercoinsaleployer合同的顶部,我们添加了以下变量来存储此合同将要部署的PupperCoin和PupperCoinSale合同的地址:

一个名为token_sale_address的公共地址,它将在部署后存储PupperCoinSale的地址。

一个名为token_address的公共地址,一旦部署,它将存储PupperCoin的地址。

在构造函数中,

我们通过定义像PupperCoin token这样的变量并将其设置为等于new PupperCoin()来创建PupperCoin令牌。在newpuppercoin的参数内部,我们传递了name和symbol变量。对于PupperCoin期望的初始_supply变量,我们传递了0。

例如:

PupperCoin token = new PupperCoin(name, symbol, 0); 

然后,我们使用token_address=address(token)存储令牌的地址。

接下来,我们使用创建PupperCoin令牌时使用的相同逻辑创建PupperCoinSale契约实例。我们将变量存储在PupperCoinSale中,并设置参数:

rate,硬编码为1,以保持与乙醚相同的单位。

钱包,从主构造器传入,这是一个钱包,它将通过PupperCoinSale筹集到的所有以太币来获得报酬。

token,存储PupperCoin的实际令牌变量。

cap,乙醚中的总容量。

目标,300以太目标。

开放,众筹开始时间。

结束,众筹结束时间。

我们再次将PupperCoinSale的地址存储在token_sale_address变量中,以便以后访问。

最后,我们将PupperCoinSale合同设置为minter,然后从puppercoinsaleployer合同中放弃“mintership”,如下:

令牌.addMinter(代币销售地址);

令牌。放弃者();

我们需要这样做,因为当我们将令牌设置为ERC20MainTable时,这个消息发送者自动设置为默认的最小值。因为puppercoinsaleployer实际上消息发送者在这种情况下,这一步将确保PupperCoinSale是实际的造币厂,正如预期的那样。

contract puppercoinsaleployer{

address public token_sale_address; address public token_address;  constructor(     string memory name,     string memory symbol,     address payable wallet, // this address will receive all Ether raised by the sale     uint cap, // Total cap in Ether     uint goal // The minimum goal in Ether  )      public       {     // create the PupperCoin and keep its address handy     PupperCoin token = new PupperCoin(name, symbol, 0);     token_address = address(token);      // create the PupperCoinSale and tell it about the token, set the goal, and set the open and close times to now and now + 24 weeks,     PupperCoinSale puppercoinSale = new PupperCoinSale(1, wallet, token, cap, goal, now, now + 24 weeks);     token_sale_address = address(puppercoinSale);      // make the PupperCoinSale contract a minter, then have the PupperCoinSaleDeployer renounce its minter role     token.addMinter(token_sale_address);     token.renounceMinter(); } 

}

Testing the Crowdsale

要发送以太并取回PUP,您需要使用部署的合同的approve功能,输入地址和您正在花费的金额,并在MetaMask上确认交易以完成交易(见屏幕截图)。

我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

Update README.md

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

www.interchains.cc

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

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

提供最优质的资源集合

立即查看 了解详情