I have a simple contract transaction that creates another contract. This transaction when called from Node.js using Web3
and truffle-contract
throws a revert.
ContractFactory.deployed().then(function(instance) {
return instance.createStore({from: accounts[0]});
});
Result:
2018-05-14T07:34:58.260Z develop:testrpc Transaction: 0xc93859052bea36bd76c80ab21d30c90a3002303ec7eb1e3ea6d08cd002990d74
2018-05-14T07:34:58.261Z develop:testrpc Gas usage: 89462
2018-05-14T07:34:58.261Z develop:testrpc Block Number: 39
2018-05-14T07:34:58.261Z develop:testrpc Block Time: Mon May 14 2018 13:04:58 GMT+0530 (India Standard Time)
2018-05-14T07:34:58.261Z develop:testrpc Runtime Error: revert
When I call the same transaction from truffle console
or truffle develop
the transaction succeeds.
truffle (develop) > ContractFactory.deployed().then(function (instance) { return instance.createStore() });
Result:
2018-05-14T07:30:33.789Z develop:testrpc Transaction: 0xbdc51bb74de2b59e98ad1b8f38ed4367c2d975a77340d778e44ee2ced969e5b9
2018-05-14T07:30:33.789Z develop:testrpc Gas usage: 135843
2018-05-14T07:30:33.789Z develop:testrpc Block Number: 38
2018-05-14T07:30:33.789Z develop:testrpc Block Time: Mon May 14 2018 13:00:33 GMT+0530 (India Standard Time)
2018-05-14T07:30:33.789Z develop:testrpc
2018-05-14T07:30:33.791Z develop:testrpc eth_getTransactionReceipt
I've been trying to get truffle debug
to work but it fails to debug transactions that create another contract.
My initial guess was that my Web3 transaction is running out of set gas limit, but would that throw a revert? I've tried setting gas limit to a very high value but with no better results.
ContractFactory.defaults({
gasLimit: "100000000000000000"
});
Contract Code:
pragma solidity ^0.4.16;
contract SimpleStore {
uint public value;
function SimpleStore (uint num) public {
value = num;
}
function setValue (uint num) public {
value = num;
}
}
contract ContractFactory {
address public store;
function ContractFactory () public {
}
function createStore () public {
store = new SimpleStore(12);
}
}
Note: Other transactions and calls work very well with the Web3 setup. This problem is common for all transactions that create a contract.