1

Sorry for the wide headline, but my problem seems almost silly to me. I'm trying to get into solidity and it looks very basic to me.

Essentially that I have two funcs (and I tested it exactly like this):

... more contract here 

  mapping(address => address) ownerToDataProvider;

  function foo(address _account) external {
    ownerToDataProvider[msg.sender] = _account;
  }

  function bar() external view returns(address) {
    return ownerToDataProvider[msg.sender];
  }

... more contract here 

And this test:

// contract is the deployed contract and dp is some address, so is user
console.log(dp)
await contract.foo(dp, {from: user})
const result = await contract.bar()
console.log(result)

The logged output is

0xf17f52151ebef6c7334fad080c5704d77216b732
0x0000000000000000000000000000000000000000

These should be equal, right? Why aren't they?

I use latest truffle and ganache.

2

Because your not passing from address to bar(). While inserting your msg.sender is nothing but from in your case.

ownerToDataProvider[msg.sender] = _account

So, while calling bar(), from value is 0x000 address, there is no value in map so it will return 0x0000000000000000000000000000000000000000

Fix:

const result = await contract.bar({from: user})

ownerToDataProvider[msg.sender] is user, so you will get 0xf17f52151ebef6c7334fad080c5704d77216b732

1

try with:

const result = await contract.bar({from: user})

Specifying the account that calls your bar() function

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.