2

this very simple factory pattern is not working on rinkeby for some reason. Using truffle v3.4.5 and geth 1.7.3-stable. Here are the contracts:

pragma solidity ^0.4.11;

contract Factory {

  address[] public pizzas;

  function Factory() {
    // constructor
  }

  function cookPizza() returns (address _pizza) {
    Pizza newPizza = new Pizza();
    pizzas.push(newPizza);
    return newPizza;
  }

  function getPizzas() public constant returns (address[]) {
    return pizzas;
  }
}

contract Pizza {
  function Pizza() {
    // constructor
  }
}

When I deploy on ganache-cli and run:

truffle(development)> Factory.deployed().then(function(instance) { factory = instance})
undefined
truffle(development)> factory.cookPizza()
truffle(development)> factory.getPizzas()
[ '0xc4f8cf2d5a37e74981fffdab1b2108931822359a' ]

It creates a new address, appends and getPizzas shows me the addresses. When I deploy on rinkeby with the following:

Running migration: 1_initial_migration.js
  Deploying Migrations...
  Migrations: 0x42e40188763019dd09a6166b76805d329bd71111
Saving successful migration to network...
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying Factory...
  Factory: 0xb9d60d9ddf16e3af3bce774a1e9286ecf5614166
Saving successful migration to network...
Saving artifacts...

In the console:

> sender = eth.accounts[0]
> abi = "abi"
> contract = eth.contract(abi)
> factory = contract.at("0xb9d60d9ddf16e3af3bce774a1e9286ecf5614166")
> factory.cookPizza({from:sender})
"0xf0ce6f4c0a9665f593d3d837eca4977b85d011dcb3620bf3a2428d25225db967"
> factory.getPizzas()
[]

Nothing. What could be causing this?

6
  • Is your contract abi equal to "abi" or you did this just to simplify? Commented Nov 24, 2017 at 11:11
  • It's simplified :) Commented Nov 24, 2017 at 11:11
  • how did you start your console? Commented Nov 24, 2017 at 11:17
  • geth attach ipc:/Users/mokn1/Library/Ethereum/rinkeby/geth.ipc Commented Nov 24, 2017 at 11:18
  • and how did you start your rinkeby node? are you using light version? If yes, it is not sync the states Commented Nov 24, 2017 at 12:15

1 Answer 1

3

I checked your transaction and it failed. https://rinkeby.etherscan.io/tx/0xf0ce6f4c0a9665f593d3d837eca4977b85d011dcb3620bf3a2428d25225db967

That´s why getPizzas() is returning an empty array.

Add funds to account[0] and unlock it and try again. It should work.

8
  • My account has 23 eth rinkeby.etherscan.io/address/…. Are you able to interact with the contract? Commented Nov 24, 2017 at 12:22
  • Yes. I tried Remix and it worked. My local Rinkeby node is not sync and I will have to wait until I can use geth console to interact with your contract. Did you unlock your account before calling cookPizza()? Commented Nov 24, 2017 at 12:25
  • Yes, it's unlocked. The tx goes through but is failing. Commented Nov 24, 2017 at 12:29
  • my last suggestion would be increase gas. factory.cookPizza({from:sender , gas: 3000000 }) Commented Nov 24, 2017 at 12:37
  • That worked! I had the default gas at 2000000.. should have been enough? Commented Nov 24, 2017 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.