我一直在尝试使用松露框架部署合同,我最近一直在开发网络上测试这些合同。
我的合同非常大,当我试图将其部署到测试网中时,我被指示将其拆分,以使合同不会超过气体限制。虽然,请记住该合同的确将其部署到具有默认气体限制的开发网络上。
因此,我取出了合同的一部分,并从基地获得了另一个合同,并在其中添加了已删除的部分。我试图将其部署到开发网络以再次进行测试,现在我会发现错误:
'Error: The contract code couldn't be stored, please check your gas amount.'
所以我采取的步骤是:
- 将我的气候更改为100,000,000,但无法解决
检查我的合同是否为"抽象"
- 我对此的理解是,合同是抽象的父母在没有实施的情况下具有任何功能。我的不。
然后派生合同,我仍然会遇到此错误
我删除了该文件,部署仅像以前一样与我的基本合同一起使用,因此,当我试图从中得出空的合同时,母公司合同不得具有任何不实用的功能,并且它仍然不起作用(制作当然,在派生合同中没有任何抽象)。
- 然后我将迁移文件拆分,以便迁移发生单独,仍然没有运气。
我的父合同长约300行,因此在这里发布所有内容 - 我知道有些人会说"它可能太大了",但是,当它在Dev Network上长500行时,它已部署它只有250行长,派生合同长275行,但不会部署。
错误:
Running migration: 2_deploy_contracts.js
Replacing ERC20Token...
... 0xcae613274de1aa278e7ae5d1239f43445132a417d98765a4f227ea2439c9e4fc
ERC20Token: 0xeec918d74c746167564401103096d45bbd494b74
Replacing Crowdsale...
... 0x0ffc7291d84289c1391a81ed9f76d1e165285e3a3eadc065732aa288ea049b3a
Crowdsale: 0x0d8cc4b8d15d4c3ef1d70af0071376fb26b5669b
Saving successful migration to network...
... 0x7f351d76f61f7b801913f59b808688a2567b64933cdfdcf78bb18b0bf4e4ff69
Saving artifacts...
Running migration: 3_more_deployed_contracts.js
Deploying StagedSale...
... 0x216136bb24d317b140a247f10ec4d6791559739111a85932133cd4a66b12a1d9
Error encountered, bailing. Network state unknown. Review successful
transactions manually.
Error: The contract code couldn't be stored, please check your gas
amount.
at Object.callback
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329221:46)
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:39618:25
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:331159:9
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:175492:11
at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:314196:9
at XMLHttpRequest.request.onreadystatechange
(/usr/local/lib/node_modules/truffle/build/cli.bundled.js:329855:7)
我的基本合同太大而无法发布,并且它自己部署正常,这意味着它不是抽象的。
我的派生合同是:
pragma solidity ^0.4.16;
import "./SafeMath.sol";
import "./Crowdsale.sol";
contract StagedSale is Crowdsale {
using SafeMath for uint256;
/*
* Setup the contract and transfer ownership to appropriate beneficiary
*/
function StagedSale
(
uint256 _stage1Duration,
uint256 _stage2Duration
) public {
uint256 stage1duration = _stage1Duration.mul(1 minutes);
uint256 stage2duration = _stage2Duration.mul(1 minutes);
}
我的派生合同迁移文件:
var StagedSale = artifacts.require("./StagedSale.sol");
module.exports = function(deployer) {
const stage1Duration = 1;
const stage2Duration = 1;
deployer.deploy(StagedSale, stage1Duration, stage2Duration);
};
我在这里发布了这个问题,因为我担心这可能是松露部署的常见问题。
得出结论,我认为这与实际的气体限制无关,而是由于某些未知原因而失败并打印此错误消息。
我已经找到了解决方案,基本上,如果您是从基本合同中继承的,则必须在继承的合同构造函数中部署基本合同:
旧版本:
简单地部署了基础,然后用class Name中的" is Crowdsale"部署了继承合同
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Crowdsale, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
deployer.deploy(FinalizableSale);
新版本
仅部署继承合同并在该构造函数中创建基础的新实例
deployer.deploy(ERC20Token, initialAmount, tokenName, decimalUnits,tokenSymbol).then(function() {
return deployer.deploy(Finalizable, softCap, hardCap, etherCostOfEachToken, sendFundsTo, toChecksumAddress(ERC20Token.address), durationInMinutes);
});
最终构造函数:
function FinalizableSale(uint256 _fundingGoalInEthers, uint256 _fundingLimitInEthers, uint256 _etherCostOfEachToken, address _sendFundsTo, address _tokenAddress, uint256 _durationInMinutes)
Crowdsale(_fundingGoalInEthers, _fundingLimitInEthers, _etherCostOfEachToken, _sendFundsTo, _tokenAddress, _durationInMinutes)
{
//do something
}
注意:基本合同是在构造函数函数的打开括号之前初始化的。
我不再遇到"无气"错误,我的合同像以前一样运行。