2

This question already has an answer here:

I have a contract datafactorycontract that calls another contract dataproducercontract. For that, in datafactorycontract I have a mapping that stores the address of the dataproducercontract being its name the key.I create the dataproducercontract on my own and then pass the address and the name to a function in the datafactorycontract. Code:

contract DataBankFactory
{

 address owner;
 mapping (string => address) dataProducerContracts;


    // Constructor
 function DataBankFactory()
 {
    owner = msg.sender;
 }

 function setProducer (string name, address add) returns (bool)
 {
    if(msg.sender == owner)
    {
        dataProducerContracts[name] = add;
        NewProducerContractAdded (name);
        return true;
    }
 }

 function getProducerAddress (string name) returns (address)
 {
    return dataProducerContracts[name];
 }
}

contract DataBankProducerContract
{
 string pname;
 uint balance;
 function DataBankProducerContract(string name, uint initbalance)
 {
    pname = name;
    balance = initbalance;
 }

}

Then, in javascript, I try to get the address of the contract stored:

var factoryAddress = HARDCODED_VALUE;
var hcproducerAddress = HARDCODED_VALUE;
var producerAddress;

factory= web3.eth.contract(ABIFACTORY).at(factoryAddress);

var producerAddress = factory.getProducerAddress(sender);
console.log('hardcoded producer address:' + hcproducerAddress);
console.log('obtained producer address:' + producerAddress); 

being the result different:

hardcoded producer address:0x2a5e1E82bBf8CeEfacb72c3103Cb531942d36cC8
obtained producer address:0x03e29a82321f451f674edbd85178b4fe7013b43ca0376868903cecdd2649f48c

This last "address" varies every time

Does anybody know what I am doing wrong here? I've checked examples, and it looks things are done like this. I do not know what is it I am getting when I retrieve the address.

marked as duplicate by eth Jun 2 '16 at 8:29

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.