Is the msg.sender address changed while passing to another contract as a parameter?

0 votes

I'm here to ask my problem on solidity code.

Here is simple example code. Contract 'Map' has a mapped data. It has each address's T/F values. I created an account X and add it to 'simpleMap'.

Contract 'Ask' lookup mapping data through 'Map' contract. What I expected result when X called askMe() was TRUE but it was always FALSE.

When I called whoIsMsgSender it returns the exact X's account. What's the problem??

pragma solidity ^0.4.24;

contract Map {
    mapping (address => bool) simpleMap;

    function add(address _address) external {
        simpleMap[_address] = true;
    }

    function isTrue(address _address) external view returns (bool _ret) {
        return simpleMap[_address];
    }
}

contract Ask {
    Map public map = Map(Map's address like 0x~~ just for test);
    function askMe() external view returns (bool _ret) {
        return map.isTrue(msg.sender);
    }

    function whoIsMsgSender() external view returns (address _address) {
        return msg.sender;
    }
}
Oct 10, 2018 in Blockchain by slayer
• 29,170 points
33 views

1 answer to this question.

0 votes

I tried your contracts in Remix, but askMe() returned true for me. How are you separating the two contracts? Maybe Map is not yet deployed before Ask is trying to call a function on it. I separated the two contracts:

pragma solidity ^0.4.24;

contract Map {
    mapping (address => bool) simpleMap;

    function add(address _address) external {
        simpleMap[_address] = true;
    }

    function isTrue(address _address) external view returns (bool _ret) {
        return simpleMap[_address];
    }
}


pragma solidity ^0.4.24;

contract Map { function isTrue(address _address) external view returns (bool _ret); }

contract Ask {
    Map public map = Map(MAP_ADDRESS);
    function askMe() external view returns (bool _ret) {
        return map.isTrue(msg.sender);
    }

    function whoIsMsgSender() external view returns (address _address) {
        return msg.sender;
    }
}
answered Oct 10, 2018 by Omkar
• 67,600 points

Related Questions In Blockchain

0 votes
1 answer

How do I send back ethers to the sender of the tokens in a smart contract?

Whenever a smart contract receives ether via ...READ MORE

answered May 30, 2018 in Blockchain by Perry
• 17,020 points
416 views
0 votes
2 answers
0 votes
1 answer

Is it possible to send eth to a contract through its constructor from another contract?

I found the solution for this: pragma solidity ...READ MORE

answered Sep 26, 2018 in Blockchain by slayer
• 29,170 points
89 views
+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 26, 2018 in Blockchain by Johnathon
• 9,080 points
78 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
156 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,600 points
88 views
0 votes
2 answers
0 votes
1 answer