I have a question for you guys. I have 2 contracts:

contract House { 
  uint public idHouse;

contract ArrayHouse { 
  House[] public arrayHouse;

  function getHouse(uint n) returns(House){
    if (n >= arrayHouse.length) 
    return arrayHouse[n];

I compiled and migrated the contract ArrayHouse to the testrpc reseau. Then, I went to truffle console and tried the following javascript:

  1. arrayHouse=ArrayHouse.new(...);

  2. arrayHouse.then(function(inst1){meta=inst1;return meta.getHouse(0)}).then(function(inst2){return inst2.idHouse.call();})

I got the following error:

TypeError: Cannot read property 'call' of undefined
    at evalmachine.<anonymous>:1:84
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)

I wonder why I cannot access to the an attribute(public idHouse) of an element(House) of my array(arrayHouse). Anyone has an idea?

2 Answers 2


Only making a guess as I cannot test it at the moment but it seems the way access your contract may be causing the issue. Then() should be used on a function to execute after the promise is returned, whereas you are using it on a variable. Try something like this:

ArrayHouse.new({from: accountAddress});

//Or use ArrayHouse.deployed() ArrayHouse.at(accountAddress).getHouse(0).then(function(inst2){return inst2.idHouse.call(); })


getHouse throws error when n is equal to arrayHouse.length. You're passing 0 and array is empty so.. you have an exception being thrown.

Other thing is that idHouse is just an attribute, so you can't call it as it was a method.

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.