solidity_advanced_homework – 坚实的家庭作业区块链毕设代写
区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,solidity_advanced_homework – 坚实的家庭作业区块链毕设代写 是一篇很好的国外资料
solidity_advanced_homework
“Crowdsale of PupperCoin token to fund network development.”
Purpose
In this project, we are using Smart Contracts to create our company’s token (PupperCoin) and to set up a Crowdsale to raise funds for our network development. Our PupperCoinCrowdSale will run for 24 weeks, and will be a refundable crowdsale to enable refunds if our goal is met. Additionally, we will be limiting our raised funds to a cap of 300 Ether.
The PupperCoin Contract
The PupperCoin
contract is a standard ERC20
, ERC20Mintable
and ERC20Detailed
contract. In order to bootstrap our contract with each of these token contracts’ properties, we need to declare this.
contract PupperCoin is ERC20, ERC20Detailed, ERC20Mintable {
In the contract’s constructor
we are setting parameters for name
, symbol
, and initial_supply
, all of which will be left with unassigned values to assign at contract deployment.
string memory name, string memory symbol, uint initial_supply
Since ERC20Detailed
requires name
, symbol
and decimals
parameters in its constructor
, we need to call it from within our contract’s constructor
// ERC20Detailed constructor parameters ERC20Detailed(name, symbol, 18)
The body of the constructor
can remain empty since all functions such as mint
, transfer
, approve
, and allowance
are inherited from the ERC20
contracts.
The PupperCoinCrowdSale Contract
The PupperCoinCrowdSale
contract is a standard Crowdsale contract that inherits properties from the following OpenZepellin
contracts: Crowdsale
, MintedCrowdsale
, CappedCrowdsale
, TimedCrowdsale
, and RefundablePostDeliveryCrowdsale
so we need to declare this in our contract’s creation.
contract PupperCoinCrowdSale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, RefundablePostDeliveryCrowdsale {
In the contract’s constructor
we need to enter parameters that are required for our standard ERC20
and Crowdsale
contracts. Since our PupperCoin
contract is compatible with the IERC20
interface that the Crowdsale
contracts require, we can use it as our token
object.
string memory name, string memory symbol, address payable wallet, uint goal, uint cap, uint rate, uint openingTime, uint closingTime, PupperCoin token
We also need to call each contract’s required constructor
parameters inside our constructor
.
Crowdsale(rate, wallet, token) RefundableCrowdsale(goal) TimedCrowdsale(openingTime, closingTime) CappedCrowdsale(cap)
The body of the constructor
can remain empty since all functions such as buyTokens
, claimRefund
, withdrawTokens
, and finalize
are inherited from the Crowdsale
contracts.
The PupperCoinCrowdSaleDeployer Contract
The PupperCoinCrowdSaleDeployer
contract will enable us to deploy both, the PupperCoin
and PupperCoinCrowdSale
contracts from a single point.
We will need to fetch the deployed contracts’ addresses, so we need to create variables for these.
address public token_sale_address; address public token_address;
The Deployer contract’s constructor
will also need the sale contract’s parameterers so they can be set at deployment.
string memory name, string memory symbol, address payable wallet, uint goal, uint cap, uint rate, uint openingTime, uint closingTime, PupperCoin token
The Deployer will also need to pass the token and crowdsale contracts by defining new variables so that it can deploy them. The parameters for both contracts will need to be passed into the new variables as well. The openingTime
and closingTime
for the PupperCoinCrowdSale
parameters can be changed to now
and now + 24 weeks
.
PupperCoin token = new PupperCoin(name, symbol, 0); PupperCoinCrowdSale pupper_sale = new PupperCoinCrowdSale(name, symbol, wallet, goal, cap, rate, now, now + 24 weeks, token);
In order for the Deployer to store the token and crowdsale contract addresses, these will need to be assigned to the variables that we created at the start of the PupperCoinCrowdSaleDeployer
contract.
token_address = address(token); token_sale_address = address(pupper_sale);
Lastly, the minter role will need to be given back to the PupperCoinCrowdSale
contract and renounced by the PupperCoinCrowdSaleDeployer
contract.
token.addMinter(token_sale_address); token.renounceMinter();
Deployment and Testing
Deploy the contract to your LocalHost first and test it by sending it Ether.
Connect the token to MyCrypto
and test some transactions.
Deploy the contract to the Kovan
testnet and test it by sending it Ether. Since Ether balances on the testnet are lower, reduce the goal
and the cap
before deploying.
Updated directions for Screenshots
稳固性高级作业
“众售PupperCoin token为网络发展提供资金。”
目的
在这个项目中,我们使用智能合约来创建我们公司的token(PupperCoin),并建立众售来为我们的网络发展筹集资金。我们的PupperCoinCrowdSale将持续24周,并将是一个可退款的众售,以使退款,如果我们的目标得到实现。此外,我们将限制我们的募集资金上限为300英镑。
布偶合同
木偶合同是标准的ERC20、ERC20可维护和ERC20详细合同。为了用这些令牌契约的每个属性引导我们的契约,我们需要声明这个。
contract PupperCoin is ERC20, ERC20Detailed, ERC20Mintable {
在合同的构造函数中,我们正在设置名称、符号和初始供应的参数,所有这些参数都将保留未分配的值,以便在合同部署时分配。
string memory name, string memory symbol, uint initial_supply
由于ERC20Detailed需要其构造函数中的名称、符号和小数参数,因此我们需要从合同的构造函数中调用它
// ERC20Detailed constructor parameters ERC20Detailed(name, symbol, 18)
构造函数的主体可以保持为空,因为所有函数(如mint、transfer、approve和allowance)都继承自ERC20合同。
布偶合同
PupperCoinCrowdSale合同是一个标准的众售合同,它继承了以下OpenZepellin合同的属性:众售、MintedCrowdsale、CappedCrowdsale、TimedCrowdsale和ReturnablePostDeliveryCrowdsale,因此我们需要在合同创建时声明这一点。
contract PupperCoinCrowdSale is Crowdsale, MintedCrowdsale, CappedCrowdsale, TimedCrowdsale, RefundablePostDeliveryCrowdsale {
在合同的构造函数中,我们需要输入标准ERC20和众售合同所需的参数。由于我们的PupperCoin合同与众包合同要求的IERC20接口兼容,因此我们可以将其用作令牌对象。
string memory name, string memory symbol, address payable wallet, uint goal, uint cap, uint rate, uint openingTime, uint closingTime, PupperCoin token
我们还需要在构造函数中调用每个契约所需的构造函数参数。
Crowdsale(rate, wallet, token) RefundableCrowdsale(goal) TimedCrowdsale(openingTime, closingTime) CappedCrowdsale(cap)
构造函数的主体可以保持为空,因为所有函数(如buyTokens、ClaimReturn、DrawTokens和finalize)都是从众售合同继承的。
The PupperCoinCrowdSaleDeployer Contract
PupperCoinCrowdSaleDeployer合同将使我们能够从一个点部署PupperCoin和PupperCoinCrowdSale合同。
我们需要获取已部署合约的地址,因此需要为这些地址创建变量。
address public token_sale_address; address public token_address;
部署者合同的构造函数还需要销售合同的参数,以便在部署时进行设置。
string memory name, string memory symbol, address payable wallet, uint goal, uint cap, uint rate, uint openingTime, uint closingTime, PupperCoin token
部署者还需要通过定义新变量来传递代币和众售合同,以便部署它们。两个契约的参数也需要传递到新的变量中。PupperCoinCrowdSale参数的打开时间和关闭时间可以更改为now和now+24周。
PupperCoin token = new PupperCoin(name, symbol, 0); PupperCoinCrowdSale pupper_sale = new PupperCoinCrowdSale(name, symbol, wallet, goal, cap, rate, now, now + 24 weeks, token);
为了让部署者存储token和crowdsale合约地址,需要将这些地址分配给我们在puppercouncrowdsaledeployer合约开始时创建的变量。
token_address = address(token); token_sale_address = address(pupper_sale);
最后,minter角色需要返还给PupperCoinCrowdSale合同,并由PupperCoinCrowdSaleDeployer合同放弃。
token.addMinter(token_sale_address); token.renounceMinter();
Deployment and Testing
首先将契约部署到本地主机,然后通过发送它来测试它。
将令牌连接到MyCrypto并测试一些事务。
将契约部署到Kovan testnet并通过发送它来进行测试。因为testnet上的以太平衡较低,所以在部署之前减少目标和上限。
<
>
Updated directions for Screenshots
部分转自网络,侵权联系删除区块链源码网
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » solidity_advanced_homework – 坚实的家庭作业区块链毕设代写