Skip to main content
added 1 character in body
Source Link
thalsky
  • 105
  • 1
  • 4

I wrote a contract A that creates a new contract B and returns the address of the new contract B that's been created. When I tested this on solidity browser it seems to work well, but when I tried to run the create method using web3, I keep getting this error:

        throw errors.InvalidResponse(result);
    ^
Error: VM Exception while processing transaction: out of gas

Here's my contract code:

pragma solidity ^0.4.2; 
contract B { 
   int public id;
   function B(int _id) { 
     id = _id;
   }
} 

contract A { 
   address Baddress;
   function createB(int _id) returns (address) { 
     Baddress = new B(_id); 
     return Baddress;
   } 
}

Here's my Javascript code that attempts to run A's createB method:

web3.eth.defaultAccount = web3.eth.coinbase;
var Acontract = web3.eth.contract([{"constant":false,"inputs":[],"name":"getdum","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"num","type":"int256"}],"name":"create","outputs":[],"payable":false,"type":"function"}]);

var A = Acontract.new({from: web3.eth.accounts[0], 
data: '{{compiled byte code}}', 
gas: '47000000'}, function (e, contract){
   console.log(e, contract);
   if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address);
     contract.createcreateB(5000).then(console.log); // This line throws the error
   }
})

I've read many other related posts and could only find answers that suggest to use more gas, but no matter how much gas I sent with the transaction, it would throw the same error. You can see I'm using a really large value for gas in the code. Can anyone help me identify what I'm doing wrong? I'm using solc Version: 0.4.9+commit.364da425.Darwin.appleclang, EthereumJS TestRPC v3.0.3, and node v6.4.0.

I wrote a contract A that creates a new contract B and returns the address of the new contract B that's been created. When I tested this on solidity browser it seems to work well, but when I tried to run the create method using web3, I keep getting this error:

        throw errors.InvalidResponse(result);
    ^
Error: VM Exception while processing transaction: out of gas

Here's my contract code:

pragma solidity ^0.4.2; 
contract B { 
   int public id;
   function B(int _id) { 
     id = _id;
   }
} 

contract A { 
   address Baddress;
   function createB(int _id) returns (address) { 
     Baddress = new B(_id); 
     return Baddress;
   } 
}

Here's my Javascript code that attempts to run A's createB method:

web3.eth.defaultAccount = web3.eth.coinbase;
var Acontract = web3.eth.contract([{"constant":false,"inputs":[],"name":"getdum","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"num","type":"int256"}],"name":"create","outputs":[],"payable":false,"type":"function"}]);

var A = Acontract.new({from: web3.eth.accounts[0], 
data: '{{compiled byte code}}', 
gas: '47000000'}, function (e, contract){
   console.log(e, contract);
   if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address);
     contract.create(5000).then(console.log); // This line throws the error
   }
})

I've read many other related posts and could only find answers that suggest to use more gas, but no matter how much gas I sent with the transaction, it would throw the same error. You can see I'm using a really large value for gas in the code. Can anyone help me identify what I'm doing wrong? I'm using solc Version: 0.4.9+commit.364da425.Darwin.appleclang, EthereumJS TestRPC v3.0.3, and node v6.4.0.

I wrote a contract A that creates a new contract B and returns the address of the new contract B that's been created. When I tested this on solidity browser it seems to work well, but when I tried to run the create method using web3, I keep getting this error:

        throw errors.InvalidResponse(result);
    ^
Error: VM Exception while processing transaction: out of gas

Here's my contract code:

pragma solidity ^0.4.2; 
contract B { 
   int public id;
   function B(int _id) { 
     id = _id;
   }
} 

contract A { 
   address Baddress;
   function createB(int _id) returns (address) { 
     Baddress = new B(_id); 
     return Baddress;
   } 
}

Here's my Javascript code that attempts to run A's createB method:

web3.eth.defaultAccount = web3.eth.coinbase;
var Acontract = web3.eth.contract([{"constant":false,"inputs":[],"name":"getdum","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"num","type":"int256"}],"name":"create","outputs":[],"payable":false,"type":"function"}]);

var A = Acontract.new({from: web3.eth.accounts[0], 
data: '{{compiled byte code}}', 
gas: '47000000'}, function (e, contract){
   console.log(e, contract);
   if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address);
     contract.createB(5000).then(console.log); // This line throws the error
   }
})

I've read many other related posts and could only find answers that suggest to use more gas, but no matter how much gas I sent with the transaction, it would throw the same error. You can see I'm using a really large value for gas in the code. Can anyone help me identify what I'm doing wrong? I'm using solc Version: 0.4.9+commit.364da425.Darwin.appleclang, EthereumJS TestRPC v3.0.3, and node v6.4.0.

edited tags
Link
Matthew Schmidt
  • 7.3k
  • 1
  • 24
  • 35
Source Link
thalsky
  • 105
  • 1
  • 4

Contract creating another contract using Web3 getting out of gas error despite gas value being large (e.g. 50,000,000)

I wrote a contract A that creates a new contract B and returns the address of the new contract B that's been created. When I tested this on solidity browser it seems to work well, but when I tried to run the create method using web3, I keep getting this error:

        throw errors.InvalidResponse(result);
    ^
Error: VM Exception while processing transaction: out of gas

Here's my contract code:

pragma solidity ^0.4.2; 
contract B { 
   int public id;
   function B(int _id) { 
     id = _id;
   }
} 

contract A { 
   address Baddress;
   function createB(int _id) returns (address) { 
     Baddress = new B(_id); 
     return Baddress;
   } 
}

Here's my Javascript code that attempts to run A's createB method:

web3.eth.defaultAccount = web3.eth.coinbase;
var Acontract = web3.eth.contract([{"constant":false,"inputs":[],"name":"getdum","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"num","type":"int256"}],"name":"create","outputs":[],"payable":false,"type":"function"}]);

var A = Acontract.new({from: web3.eth.accounts[0], 
data: '{{compiled byte code}}', 
gas: '47000000'}, function (e, contract){
   console.log(e, contract);
   if (typeof contract.address !== 'undefined') {
     console.log('Contract mined! address: ' + contract.address);
     contract.create(5000).then(console.log); // This line throws the error
   }
})

I've read many other related posts and could only find answers that suggest to use more gas, but no matter how much gas I sent with the transaction, it would throw the same error. You can see I'm using a really large value for gas in the code. Can anyone help me identify what I'm doing wrong? I'm using solc Version: 0.4.9+commit.364da425.Darwin.appleclang, EthereumJS TestRPC v3.0.3, and node v6.4.0.