Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The error "Error: The contract code couldn't be stored, please check your gas amount." shows up when deploying Crowdsale contract on Ropsten/Rinkeby. #984

Closed
sheraz104-zz opened this issue Jun 7, 2018 · 20 comments

Comments

@sheraz104-zz
Copy link

sheraz104-zz commented Jun 7, 2018

image
I've tried increasing gas to maximum, and tried debugging the code looking for potential issues to no avail. The contract deploy on ganache/TestRPC without an issue.
Could anyone help?

@come-maiz
Copy link
Contributor

Hello @sheraz104. Many things can cause this error, and it's generally misleading. Take a look at trufflesuite/truffle#522
Check that your constructors are passing all the required arguments in the inheritance chain. Also check that your build directory is up to date.

@shrugs
Copy link
Contributor

shrugs commented Jun 8, 2018

https://vmexceptionwhileprocessingtransactionrevert.com/ may also help

@mswezey23
Copy link
Contributor

I've received this error as well when an abstract function was not implemented IIRC.

@shrugs
Copy link
Contributor

shrugs commented Jun 9, 2018

@sheraz104 please provide more info (ideally also upload your full project to github so that we can see how the contracts are deployed).

This is almost definitely an issue with your constructor arguments coming from the migration/deploy script.

@samaujs
Copy link

samaujs commented Jun 10, 2018

Hi, I have the same error message even when I changed the gas to 4700000 higher than default in truffle.js. The default "Migrations.sol" file is as follow:

pragma solidity ^0.4.23;

contract Migrations {
address public owner;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender == owner) _;
}

function Migrations() public {
owner = msg.sender;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}

Can someone share some more information how to resolve this compilation error?
I have also checked the constructors for the imported contracts "zeppelin-solidity/contracts/crowdsale/emission/MintedCrowdsale.sol" and
"zeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol". Thanks.

@samaujs
Copy link

samaujs commented Jun 10, 2018

After couple of attempts, found the information in "#358". By changing as per suggestion by spalladino in the deployment script:
"const startTime = web3.eth.getBlock(web3.eth.blockNumber).timestamp + 120"; compilation and migration can be completed.

@come-maiz
Copy link
Contributor

😆 awesome website @shrugs!!! I can see it in the short future as one of the most popular stack overflow answers.

@ghost
Copy link

ghost commented Jun 23, 2018

I'm unable to resolve the issue.
I've uploaded the crowdsale code in this google sheet.
https://docs.google.com/document/d/1BcZWr8mh96y0OWN-3TCBUlSRbM1FlJEJCAlKAm1PvL8/edit?usp=sharing
Kindly take a look @shrugs

@shrugs
Copy link
Contributor

shrugs commented Jun 24, 2018

@Sheraz-dev please upload your code to a github repo so that it's easier for people to use :)

@dhruv-karan
Copy link

dhruv-karan commented Oct 24, 2018

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface,bytecode} = require('./compile');

const provider = new HDWalletProvider(
'XXXXXXX some account newmonix XXXXXXXXXXXXXXXXXXXXXXXXXX',
'XXXXXany infura node XXXXXXXXXXXXXXXXX'
)

const web3 = new Web3(provider)

const deploy = async()=>{
const accounts = await web3.eth.getAccounts()
console.log(accounts[0]);
const result = await new web3.eth.Contract(JSON.parse(interface))
.deploy({data:bytecode,arguments:['hi']})
.send({gas:'1000000 ',from:accounts[0]})
console.log('contract deployed to',result.options.address);

}
deploy()

@dhruv-karan
Copy link

same problem

@sheraz104-zz
Copy link
Author

share your smart contract code

@kennypz562
Copy link

I got the same problem but when i remove function calling inside my constructor it works fine. Why?

@ymekuria
Copy link

@dhruv-karan . Try this in your deploy script.

change these two lines from this.
.deploy({data:bytecode, arguments: ['hi']})
.send({gas:'1000000 ', from: accounts[0]})

to this
.deploy({data: '0x' + bytecode, arguments:['hi']}) // add 0x before bytecode
.send({from:accounts[0]}) // take out the gas field

Your 1st Line
This is ok when you deploy your code in the ganache local test network.
When you deploy to another remote test network like kovan or rinkeby, you should put the '0x' as prefix in bytecode of ABI.

Your 2nd Line
When you test with ganache provider, the gas key should be specified but not in this case.
https://hanezu.github.io/posts/Gas-Limit-Error-when-deploy-Truffle-project-on-Private-Network.html

@robin9421
Copy link

image
I've tried increasing gas to maximum, and tried debugging the code looking for potential issues to no avail. The contract deploy on ganache/TestRPC without an issue.
Could anyone help?

this happens to me also, but i got the solution.
open your package.json file
and change the versions as follows:
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"ganache-cli": "^6.0.3",
"mocha": "^5.0.1",
"solc": "^0.4.20",
"truffle-hdwallet-provider": "0.0.3",
"web3": "^1.0.0-beta.26"

and after this remove node-modules and run "npm install" on terminal

@juannavas31
Copy link

@ymekuria
Thanks!! the missing '0x' before bytecode was definitely the solution in my case.
It's a bit frustrating how misleading the errors are...

@romisalve
Copy link

Hi, I am having the same problem and not getting what is causing it, can anyone help me if I share the code? Thanks!

@frangio
Copy link
Contributor

frangio commented Jun 10, 2019

@romisalve Sure. Please post on https://forum.openzeppelin.com.

@mdsalik7
Copy link

Hi, I am having the same problem and not getting what is causing it, can anyone help me if I share the code? Thanks!

.deploy({data: '0x' + bytecode, arguments:['hi']}) // add 0x before bytecode
When you deploy to another remote test network like kovan or rinkeby, you should put the '0x' as prefix in bytecode of ABI.

@tonoyandev
Copy link

Deleting the ./build folder and rebuilding solve it for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests