[英]How to deploy truffle contract to dev network when using inheritance?
我一直在嘗試使用Truffle框架部署合同,最近我在開發網絡上測試了這些合同。
我的合同非常大,當我嘗試將其部署到測試網時,系統指示我將其拆分,以使合同不會超出汽油限額。 不過,請記住,該合同確實以默認的氣體限制部署到了開發網絡上。
因此,我取出了合同的一部分,並從基礎中導出了另一個合同,並在其中添加了已刪除的部分。 我嘗試將其部署到開發網絡以再次對其進行測試,現在出現錯誤:
'Error: The contract code couldn't be stored, please check your gas amount.'
因此,我采取的步驟是:
檢查我的合同是否“抽象”
然后,我從派生合同中刪除了除構造函數以外的所有代碼,但仍然出現此錯誤
我像以前一樣刪除了文件,並且部署僅與我的基本合同一起使用,因此,父合同一定不能具有任何未實現的功能,並且當我嘗試從中獲取空合同時,它仍然不起作用(請確保沒有任何問題)衍生合同中的摘要)。
我的父合同長約300行,因此沒有必要在此處全部張貼-我知道有些人會說“它可能太大了”,但是,它在開發網絡上只有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);
};
我在此發布了此問題,因為我擔心這可能是Truffle部署的常見問題。
總而言之,我不認為這與實際的氣體限制有關,而是由於某種未知原因而失敗,並且無論如何都會打印此錯誤消息。
我已經找到了解決方法,基本上,如果您要從基本合同繼承,則必須在繼承的合同構造函數中部署基本合同,如下所示:
舊版本:
只需部署基礎,然后部署繼承合同,並在類名中引用“ 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);
新版本
僅部署繼承合同並在該構造函數中創建base的新實例
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
}
注意:基本合同是在構造函數的大括號之前初始化的。
我不再遇到“斷氣”錯誤,合同也像以前一樣運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.