I'm implementing an ERC721 contract and I want to execute the following logic.
This is what I want: If the user pass to a method an address, return that address, if not, return the user's address.
I have been playing in Remix and I have this method:
function showsender(address passsedAdd) public view returns(address) {
address addToReturn;
if(passsedAdd==address(0)) {
addToReturn = msg.sender;
}
else {
addToReturn = passsedAdd;
}
return addToReturn;
}
However, I could not make it work as I want since it looks like in Solidity arguments are NOT optional.
So, running testS... If I pass the arg, example:
console.log(
await this.contract.showsender(
'0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C'
)
);
Works, but if I try that, in case the user is not explicitly passing an argument, it doesn´t: this.contract.showsender();
I'm totally new to Solidity. Can anyone help?
this.contract.showsender()
) is invalid, even if it's allowed. The function takes a parameter, and you haven't passed one. Trythis.contract.showsender("0x000000...")
.