1

In the Eris Solidity tutorial, a system of a Bank and a FundManager contract are developed. In the fund manager constructor

contract Bank {
    [Bank contract details]

    function setOwner(address newOwner) returns (bool res) {
        if (owner != 0x0 && msg.sender != owner){
            return false;
        }
        owner = newOwner;
        return true;
    }
}

contract FundManager {

    address bank;

    // Constructor
    function FundManager(){
        owner = msg.sender;
        bank = new Bank();
        Bank(bank).setOwner(address(this));
    }
}

one sets a reference to a Bank. When I deploy the contract and mine it in a private net and then check for the bank reference of the FundManager, no reference is found (so I can't deposit, because depositing requires a bank to be set).

Here's how I deploy:

var fm_arg = "fm";
var fm = contract_fm.new(fm_arg,
                    {
                         from: eth.accounts[0],
                         data: compiled_fm.FundManager.code,
                         gas: 1000000
                    }, callback);

I would think, I should now be able to call the bank variable:

> fm.bank
undefined

Why is the bank not set when I construct the FundManager?

1

You declare bank in FundManager as an Ethereum address:

address bank;

not an instance of the contract Bank:

Bank bank;
  • Ok, but then should not fm.bank return an address? – TMOTTM Jul 18 '16 at 13:09
  • If it were initialized yes, but currently it's not. – Sebi Jul 18 '16 at 13:11
  • Thats my point: Why is it not initialized? Its in the constructor which is called when I deploy the contract! Do I need to separately deploy the bank contract and create a bank instance? – TMOTTM Jul 18 '16 at 17:48
  • Bank is of two different types in your code 1) an Ethereum address and 2) an instance of the contract Bank. Replace bank (the address) with a different name (bankAddr) in the FundManager contract. – Sebi Jul 19 '16 at 8:11
  • I was starting to think something like that... but then to me thats kind of bad practice to have a variable with the same name be totally different things. – TMOTTM Jul 19 '16 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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