I am trying to write a contract where the originator of the contract will offer a reward that can only be claimed by a different address that she or he specifies. To do that, I am trying to create state variable of type 'address' that stores the address of the person who is allowed to claim the reward, which I am calling the 'ambassador'.

See the code below:

pragma solidity ^0.4.19;    
contract AmbassadorTask {
    address private owner; // Address of business offering rewards for a task 
    uint taskReward; // How much ether ambassadors get every time they complete a task
    address ambassador; // Represents person allowed to complete task and claim rewards

    function AmbassadorTask (address _ambassador) public payable {
            require (msg.value > 0); // No point creating tasks with no rewards
            owner = msg.sender;  // Set creator to be the owner of this contract
            taskReward = msg.value;
            ambassador = _ambassador;

    function getAmbassador() public view returns (address _ambassador) {
        return ambassador;

The code compiles correctly in Remix, but when I test it at run time using the JavaScriptVM, the 'ambassador' address that is stored in the contract is not the same address that I pass as input in the constructor.

For example, I pass 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c as input, when calling the constructor. If I immediately call getAmbassador(), I get the following output: 0xa4aff308fddc160c000000000000000000000000, instead of the value I entered to create the contract. I also noticed that it is just the last 16 hex digits from the address I passed, followed by trailing zeros.

In contrast, I am not having the same issue storing msg.sender to the owner state variable when I call the constructor.

Why is this happening? I am storing the address values incorrectly? Is this a data conversion issue?

Thanks in advanced for your help!

  • Thanks for checking! I wonder if it might help to pass the address as a string and then convert it to address during the constructor, just to have a work around. Just wondering.
    – Ramon
    Commented Mar 8, 2018 at 21:26

1 Answer 1


Make sure you put quotes around the address when specifying it as a constructor parameter. Remix does a very poor job of parsing unquoted hexadecimal strings.

I could reproduce the behavior you saw only by using an unquoted hexadecimal string. With quotes, it worked correctly all 10 times I attempted it.

  • Yup!!! That did it. Thank you so much. I can't believe it was just a matter of missing quotes. Thank you very much for your help!
    – Ramon
    Commented Mar 8, 2018 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.