Crowdsale With ERC20 Token – ERC20代币众售区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Crowdsale With ERC20 Token – ERC20代币众售区块链毕设代写 是一篇很好的国外资料

Crowdsale With ERC20 Token

Crowdsale With ERC20 Token - ERC20代币众售

This Blockchain example utilizes the OpenZeppelin Solidity library to create an ERC20 token that is minted through a crowdsale contract. The contract will allow users to send ETH and get back PUP, or PupperCoin, the hypothetical name of the company’s token. The contract mints the tokens automatically and distributes them to buyers in one transaction. A real-world pre-production test is shown in which I deploy the crowdsale to the Kovan testnet.


Contract Set-Up / Deployment:

1. Use Remix to create a .sol file and create a standard ERC20Mintable token:

  • Use Standard ERC30Mintable and ERC30Detailed contracts from Open Zeppelin
  • Hardcode 18 as the decimals parameter
  • You don’t need to hardcode the decimals, however since most use-cases match Ethereum’s default, you may do so.
  • After compiling your code, fill in the Name, Symbol and Initial_Supply for your token and deploy to your local chain using MetaMask

Crowdsale With ERC20 Token - ERC20代币众售

2. Create a new .sol file to write the code for your Crowdsale:

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

3. Deploy Crowdsale to local blockchain using MetaMask:

  • Deploy contract PupperCoinSaleDeployer first, as this contract controls all the other pieces.
  • Fill out required information in Deployment dropdown before deploying contract

Crowdsale With ERC20 Token - ERC20代币众售

  • Now, switch your contract to PupperCoinSale, find the first address that was generated when you deployed the above contract (the token address), populate that address into the “At Address” field, and hit that “At Address” button. You now have an instance of your PupperCoinSale and all the additional functionality that comes with it:

Crowdsale With ERC20 Token - ERC20代币众售

  • Now do the same thing, but this time, for the PupperCoin token itself. Use the second address generated by the SaleDeployer (the token_sale address) in your “At Address” field:

Crowdsale With ERC20 Token - ERC20代币众售

4. Test Crowdsale by Purchasing Tokens:

  1. Change values from Wei to Ether, and populate that field with a number
  2. Scroll down to your PupperCoinSale Deployed Contract, grab an address from your Ganache chain (NOT the first one, the one connected to Remix), and populate the “address beneficiary” field next to the buyTokens button with that address. Click buyTokens, and let MetaMask go to work. To confirm it worked, in that same deployed contract that has the buyTokens button, use the balanceOf button to check the balance of the address you sent Ether to: it should not be empty:

more gifs


使用ERC20代币的众售

Crowdsale With ERC20 Token - ERC20代币众售

区块链blockchain示例利用OpenZeppelin Solidity库创建通过众售合同铸造的ERC20代币。该合同将允许用户发送ETH并取回PUP或pupercoin,即公司代币的假想名称。合同自动铸造代币,并在一次交易中将其分配给买家。在一个真实的预生产测试中,我将众售部署到Kovan测试网。


合同设置/部署:。使用Remix创建一个.sol文件并创建一个标准的可维护令牌:

2。创建一个新的.sol文件,为您的众包销售编写代码:

3。使用MetaMask将众售部署到本地区块链blockchain

4。通过购买代币来测试众售:

  • 使用Open Zeppelin的标准ERC30可维护和ERC30详细合同
  • 硬编码18作为小数参数
  • 您不需要硬编码小数,但是由于大多数用例都匹配以太坊eth的默认值,您可以这样做。
  • 编译代码后,填写名称,为您的代币提供符号和初始u,并使用MetaMask部署到您的本地链中,您需要通过继承以下OpenZeppelin合同来引导合同:众售
    MintedCrowdsale
    CappedCrowdsale
    TimedCrowdsale
    可退款的PostDeliveryCrowdsale
  • 您需要提供以下参数:众筹的所有功能,如名称、符号、筹款钱包、目标等,您可以根据自己的喜好随意配置这些参数。
  • 您可以将速率硬编码为1,以保持与乙醚单位的奇偶性(每乙醚1 TKN或每魏1 TKNbit)。如果您想定制您的众售率,请遵循OpenZeppelin文档中的众售率计算器。从本质上讲,一个代币(TKN)可以分为tknbit,就像以太可以分为wei一样。当使用1的速率时,就像10000000000000000 wei等于1乙醚一样,10000000000000000 TKNbits等于1 TKN。
  • 由于ReturnablePostDeliveryCrowdsale继承了ReturnableCrowdsale合同,该合同需要一个目标参数,因此您必须从PupperCoinCrowdsale构造函数以及其他构造函数中调用ReturnableCrowdsale构造函数。ReturnablePostDeliveryCrowdsale没有自己的构造函数,所以只需使用它继承的ReturnableCrowdsale构造函数即可。
  • 如果忘记调用ReturnableCrowdSale构造函数,ReturnablePostDeliveryCrowdSale将失败,因为它依赖于它(它继承自ReturnableCrowdSale),并且没有自己的构造函数。
  • 通过打开和关闭时间时,请使用“现在”和“现在+24周”从您的PupperCoinCrowdsaleDeployer合同中正确设置时间。
  • 首先部署契约puppercounsaledeployer,因为此契约控制所有其他部分。
  • 在部署合约之前,在部署下拉列表中填写所需信息
  • 现在,将合约切换到PupperCoinSale,找到部署上述合约时生成的第一个地址(令牌地址),将该地址填充到“At address”字段,然后点击“At address”按钮。现在,您有了一个PupperCoinSale的实例和它附带的所有附加功能:
  • 现在做同样的事情,但这次是针对PupperCoin令牌本身。在“At address”字段中使用SaleDeployer生成的第二个地址(tokenu sale address):
  • 将值从Wei更改为Ether,并用数字填充该字段
  • 向下滚动到PupperCoinSale部署的合同,从Ganache链中获取一个地址(不是第一个,是连接到混音的地址),并用该地址填充buyTokens按钮旁边的“地址受益人”字段。单击buytokes,让MetaMask开始工作。为了确认它是否有效,在部署了buyTokens按钮的同一个合同中,使用balanceOf按钮检查您发送到的地址的余额:它不应为空:
  • 2。创建一个新的.sol文件,为您的众包销售编写代码:

    • 使用Open Zeppelin的标准ERC30可维护和ERC30详细合同
    • 硬编码18作为小数参数
    • 您不需要硬编码小数,但是由于大多数用例都匹配以太坊eth的默认值,您可以这样做。
    • 编译代码后,填写名称,为您的代币提供符号和初始u,并使用MetaMask部署到您的本地链中,您需要通过继承以下OpenZeppelin合同来引导合同:众售
      MintedCrowdsale
      CappedCrowdsale
      TimedCrowdsale
      可退款的PostDeliveryCrowdsale

    Crowdsale With ERC20 Token - ERC20代币众售

    3。使用MetaMask将众售部署到本地区块链blockchain

    • You will need to bootstrap the contract by inheriting the following OpenZeppelin contracts: Crowdsale
      MintedCrowdsale
      CappedCrowdsale
      TimedCrowdsale
      RefundablePostDeliveryCrowdsale
    • 您需要提供以下参数:众筹的所有功能,如名称、符号、筹款钱包、目标等,您可以根据自己的喜好随意配置这些参数。
    • 您可以将速率硬编码为1,以保持与乙醚单位的奇偶性(每乙醚1 TKN或每魏1 TKNbit)。如果您想定制您的众售率,请遵循OpenZeppelin文档中的众售率计算器。从本质上讲,一个代币(TKN)可以分为tknbit,就像以太可以分为wei一样。当使用1的速率时,就像10000000000000000 wei等于1乙醚一样,10000000000000000 TKNbits等于1 TKN。
    • 由于ReturnablePostDeliveryCrowdsale继承了ReturnableCrowdsale合同,该合同需要一个目标参数,因此您必须从PupperCoinCrowdsale构造函数以及其他构造函数中调用ReturnableCrowdsale构造函数。ReturnablePostDeliveryCrowdsale没有自己的构造函数,所以只需使用它继承的ReturnableCrowdsale构造函数即可。
    • 如果忘记调用ReturnableCrowdSale构造函数,ReturnablePostDeliveryCrowdSale将失败,因为它依赖于它(它继承自ReturnableCrowdSale),并且没有自己的构造函数。
    • 通过打开和关闭时间时,请使用“现在”和“现在+24周”从您的PupperCoinCrowdsaleDeployer合同中正确设置时间。

    4。通过购买代币来测试众售:

    • 首先部署契约puppercounsaledeployer,因为此契约控制所有其他部分。
    • 在部署合约之前,在部署下拉列表中填写所需信息

    Crowdsale With ERC20 Token - ERC20代币众售

    • 现在,将合约切换到PupperCoinSale,找到部署上述合约时生成的第一个地址(令牌地址),将该地址填充到“At address”字段,然后点击“At address”按钮。现在,您有了一个PupperCoinSale的实例和它附带的所有附加功能:

    Crowdsale With ERC20 Token - ERC20代币众售

    • 现在做同样的事情,但这次是针对PupperCoin令牌本身。在“At address”字段中使用SaleDeployer生成的第二个地址(tokenu sale address):

    Crowdsale With ERC20 Token - ERC20代币众售

    4. Test Crowdsale by Purchasing Tokens:

    1. 将值从Wei更改为Ether,并用数字填充该字段
    2. 向下滚动到PupperCoinSale部署的合同,从Ganache链中获取一个地址(不是第一个,是连接到混音的地址),并用该地址填充buyTokens按钮旁边的“地址受益人”字段。单击buytokes,让MetaMask开始工作。为了确认它是否有效,在部署了buyTokens按钮的同一个合同中,使用balanceOf按钮检查您发送到的地址的余额:它不应为空:

    more gifs

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

    www.interchains.cc

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

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

    提供最优质的资源集合

    立即查看 了解详情