when I deploy a contract, the truffle frame told me this error :“The contract code couldn't be stored, please check your gas amount”。 the solidity code is:
1) Base.sol
pragma solidity ^0.4.22;
contract Base{
uint public num;
event mint(uint n);
constructor() public {
}
function Minit(uint _n) external returns (bool) {
num = _n;
emit mint(num);
return true;
}
function getN() external view returns(uint result){
result = num;
}
}
2) Extend.sol
pragma solidity ^0.4.22;
import "./Base.sol";
contract Extend{
Base public base;
uint public num;
constructor() public {
base = new Base();
base.Minit(10);
}
function setN() public{
num = base.getN();
}
function getN() public view returns(uint){
return num;
}
}
3) I run these smart contracts in a private ethereum. the genesis.json is:
{
"config": {
"chainId": 168,
"homesteadBlock":5,
"eip155Block":0,
"eip158Block":0
},
"alloc" : {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x400",
"extraData" : "",
"gasLimit" : "0xffffff",
"nonce" : "0x0000000000000042",
"mixhash" :"0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" :"0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
4) the truffle.js file is:
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
networks:{
live: {
host:"127.0.0.1",
port:8545,
network_id:"168",
from:"0xd31457ba4448cf4ec0c9b9e87e06d633cd9e5406",
gas:6500000
}
}
5) the deploy script is :2_deploy_contracts.js
var Extend = artifacts.require("./Extend.sol");
module.exports = function(deployer){
deployer.deploy(Extend);
}
6) go's verions
go version go1.10 linux/amd64
7) geth's versions
Geth
Version: 1.8.15-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: linux
GOPATH=/home/hlf/Gopath
GOROOT=/usr/local/go
so, I want to kown why I could failed? and What should I do?
Now, I found that if one contract call other contract's external function and this function have a returns value,the gas will be burned all, sample:
1) Base.sol
pragma solidity ^0.4.22;
contract Base{
address public owner;
function Mint() payable external returns(uint){
return 1;
}
constructor() public {}
}
2)Extend.sol
pragma solidity ^0.4.22;
import "./Base.sol";
contract Extend{
Base public base;
uint public es;
constructor (address _baseAdd) public {
base = Base(_baseAdd);
}
function mint() public {
es = base.Mint();
}
function getES() public view returns(uint){
return es;
}
}
when I call ExtendInst.mint() in truffle console, es = base.Mint() will consumes all the gas. why? And Is it can't use a contract's external function to return a value?
truffle migrate
works as expected. – Rob Hitchens - B9lab Sep 5 '18 at 3:22