2

I have an existing contact ManageMembers that allows new members to create a new contract via the AddMember function which also returns the address of the new contract. This works fine in the Remix Javascript virtual machine, but doesn't return the address with a Web3 provider.

contract ManageMembers {

  address[] members;

  function AddMember(bytes32 name) public returns(address) {
    address member = new Contract(name);
    members.push(member);
    return member;
  } 
}

contract Contract {
  bytes32 public Name;

  function Contract(bytes32 name) public {
    Name = name;
  }
}

I know that the new member contract has been created because the address is pushed to members and I can access other variables in the new contract. Here is output from Remix:

status 1 from 0x7598a74e87f325db2a521729208ac8f341a97a8e to ManageMembers.AddMember(bytes32) 0xad5e8618c90cef613e6b42a60c795e74fcb51594 gas 190860 gas

transaction cost 190860 gas hash 0xc2285112566da09f67f1b03e025191ae5d69ee5fa26cb486bec61a6bf0913424 input 0xd0944ada712e7140712e636f6d0000000000000000000000000000000000000000000000 decoded input { "bytes32 name": "0x712e7140712e636f6d0000000000000000000000000000000000000000000000" } decoded output - logs [] value 0 wei

I'm using testrpc which normally works fine and all account addresses are shown in Remix.

Why does this not work with Web3?

2

Transactions don't have return values. Remix + JavaScript VM show the return values of functions you call in transactions, but no real networks work that way.

You'll probably want to log an event that the client can watch for to get the address of the new contract.

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.