0

I've been getting this error when I try and deploy a contract with a constructor on multiple pieces of code. I use the correct complier version too

creation of MyContract errored: Error encoding arguments: Error: invalid address (argument="address", value="", code=INVALID_ARGUMENT, version=address/5.1.0) (argument=null, value="", code=INVALID_ARGUMENT, version=abi/5.1.2)

can anyone help?

pragma solidity 0.5.1;

contract MyContract {
    mapping(address => uint256) public balances;
    address payable wallet;
    
    constructor(address payable _wallet) public {
        wallet = _wallet;
    }
    
    function buyToken() public payable{
        //buy token
        balances[msg.sender] += 1;
        wallet.transfer(msg.value);
        //send eth to wallet
    }
}

edit: this is happening when I pass in address payable _wallet into my constructor. If I take out address payable I can deploy. This happens on my other computer too. So I know this isnt a machine related error

1
  • Hi there. Please edit your question to include at least the constructor and the way you're invoking it (i.e. your deployment parameters). – Richard Horrocks May 8 at 7:23
0

Your code is all good. Your problem is that the editor you are using is having some different version of solidity compiler installed in it. Try using that same version in your code too or else you can always use Remix editor for writing Smart Contracts.

Hope your problem is resolved

Okay so just checked it again, everything is fine. The thing is since you are passing an argument inside the constructor, so you need to provide that before deploying your smart contract. Since you are not providing it any address of an account, it throws invalid argument error.

Just copy an address, it can be the one from which you are deploying your smart contract too, paste it in arguments field next to deploy and then proceed. It will work without any problem.

All the best!

4
  • 1
    I am using the same complier version that I have stated in code on remix. Is there any other reason this would be happening. Can I call a function to change the abi version or something? – Dapper May 8 at 21:20
  • I have updated my previous answer you can check it – Lokesh Mishra May 9 at 6:48
  • I would up vote but I need more rep. You have solved my problem. You are the best. I've been at this for 3 days. THANK YOU. It was a huge aha moment – Dapper May 9 at 10:34
  • I know.. There have been times when I also used to get stuck like this In fact, I'm also a beginner like you so yeah Good Luck !! – Lokesh Mishra May 9 at 12:00

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.