Solidity
擴展眾籌智能合約未部署到測試網
我正在嘗試使用 remix IDE 將以下眾包契約(從 openzeppelin 擴展)部署到 ropsten 測試網路。 當我嘗試部署時
,契約編譯但拋出錯誤(超過氣體限制)。
這些錯誤對我來說似乎模棱兩可,因為我提高了汽油價格和限制,但仍然有同樣的問題
程式碼如下:
pragma solidity ^0.4.23; import "../node_modules/zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol"; import "../node_modules/zeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol"; import "../node_modules/zeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol"; contract SaleContract is CappedCrowdsale, RefundableCrowdsale, MintedCrowdsale { // solium-disable operator-whitespace event refund(string why, address beneficiary); event sentExternalTokens(uint256 amount); uint8 public constant decimals = 18; uint256 public presaleStarts; uint256 public crowdsaleStartTime; uint256 public presaleRate; uint256 public crowdsaleRate; uint256 public presaleRaised; uint256 public externalTokensSent; uint256 public constant maxTokens = 6000000 * 10 ** uint256(decimals); uint256 public constant totalSaleTokens = 5000000 * 10 ** uint256(decimals); uint256 public constant presaleTokens = 2000000 * 10 ** uint256(decimals); uint256 public reservedTokens = 1000000 * 10 ** uint256(decimals); /** * @dev vary rate according to block time. */ modifier rateMod { // solium-disable-next-line security/no-block-members if (block.timestamp >= crowdsaleStartTime) rate = crowdsaleRate; else rate = presaleRate; _; } /** * @dev prevent purchase when limit exceeded. */ modifier limitCheck { uint256 tokensTomint = msg.value.mul(rate); uint256 totalAfterMint = token.totalSupply() + tokensTomint; // solium-disable-next-line security/no-block-members if ((block.timestamp < crowdsaleStartTime) && (totalAfterMint > presaleTokens)) { msg.sender.transfer(msg.value); // Refund them emit refund("presale limit hit, refunding ", msg.sender); return; } _; } constructor( uint256 _openingTime, uint256 _crowdsaleStartTime, uint256 _closingTime, uint256 _presaleRate, uint256 _crowdsaleRate, uint256 _goal, uint256 _cap, MintableToken _token, address _wallet ) public Crowdsale(_presaleRate, _wallet, _token) CappedCrowdsale(_cap) TimedCrowdsale(_openingTime, _closingTime) RefundableCrowdsale(_goal) { require(_openingTime < _crowdsaleStartTime); require(_goal <= _cap); crowdsaleStartTime = _crowdsaleStartTime; presaleRate = _presaleRate; crowdsaleRate = _crowdsaleRate; } /** * @dev Extend parent behavior requiring purchase to consider emission rate based on ~time. * @param _beneficiary Token purchaser * @param _weiAmount Amount of wei contributed */ function _preValidatePurchase( address _beneficiary, uint256 _weiAmount ) internal rateMod // **set appropriate rate** limitCheck // **verify limits** { super._preValidatePurchase(_beneficiary, _weiAmount); } /** * @dev update state variables * @param _beneficiary Address performing the token purchase * @param _weiAmount Value in wei involved in the purchase */ function _updatePurchasingState( address _beneficiary, uint256 _weiAmount ) internal { // solium-disable-next-line security/no-block-members if (block.timestamp < crowdsaleStartTime) { presaleRaised = presaleRaised.add(msg.value); } super._updatePurchasingState(_beneficiary, _weiAmount); } function sendExternalTokens(address[] recipients, uint amount) onlyOwner public { require(amount > 0); uint256 totalToTransfer = recipients.length.mul(amount); require((token.totalSupply() + totalToTransfer) < maxTokens); for (uint256 i = 0; i < recipients.length; i++) { _deliverTokens(recipients[i], amount); } externalTokensSent = externalTokensSent.add(totalToTransfer); emit sentExternalTokens(totalToTransfer); } function finalize(address _reserveWallet) onlyOwner public { require(!isFinalized); uint256 existingTokens = token.totalSupply(); require(existingTokens < maxTokens); uint256 unsoldTokens = totalSaleTokens - existingTokens; if (unsoldTokens > 0) { reservedTokens = reservedTokens + unsoldTokens; } _deliverTokens(_reserveWallet, reservedTokens); super.finalize(); } }
我設法在 Rinkeby Network 上進行了部署。因此,我將介紹我的方式。
- 使用 Remix 編譯程式碼並將 MintableToken 部署到 Rinkeby
- 獲取 Mintable Token 地址,將具有已知 Mintable Token 地址的 SaleContract 部署到 Rinkeby
- 您的參數可能存在一些問題。我要初始化的參數如下
1541902893,1551902893,1571902893,3,4,5,6,"0xd40e809eefe17efca14aa4604de7f8599cdf8871","0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
Rinkeby (Mintable): https://rinkeby.etherscan.io/address/0xd40e809eefe17efca14aa4604de7f8599cdf8871 Rinkeby (SaleContract): https://rinkeby.etherscan.io/address/0xf959a499a514f80f47c
PS:我從 github 導入了 open-zeppelin 庫,建議在開發階段使用
import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol"; import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";