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,350 points
1,147 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
• 69,210 points

Related Questions In Blockchain

0 votes
1 answer

Solidity: Code to hide message sender address (msg.sender) when writing on a contract

Hey @Wilson, You can use a smart contract ...READ MORE

answered Sep 14, 2020 in Blockchain by Rajiv
• 8,910 points
1,674 views
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,100 points
3,371 views
0 votes
2 answers

Is it possible to modify a variable value from another contract?

No, you can't directly edit a variable ...READ MORE

answered Sep 24, 2018 in Blockchain by Sai
3,991 views
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,350 points
1,495 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
1,706 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,237 views
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
• 69,210 points
1,254 views
0 votes
2 answers

Why is network already up to date while trying to deploy a contract on truffle?

I guess you have ganache running already ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,400 points
4,152 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP