My question is pretty simple
I'm trying to call a function in my smart contract from ethers.js
I just need to set a variable of type "address" in my contract.
Code:
//solidity
function setTokenX(address _tokenX) public {
tokenX = _tokenX;
}
//js
tokenX = '0x3fdaf6c54eba05edebed44c4f986f49a5de55113';
await mycontract.setTokenX(tokenX);
It works a weird way for some reason. On Etherscan my variable is displayed as
0x361d47ce0000000000000000000000003fdaf6c54eba05edebed44c4f986f49a5de55113
While in the in javascript I send the parameter as a string. What's the catch? Should I encode it and then abi.decode in solidity? How to do this with ethers.js?
Best Answer
The contract should be working correctly.
The input look a little odd because it is encoded in the solidiy ABI.
361d47ce
The first four bytes is the function selector. It encodes the function to be called.0000000000000000000000003fdaf6c54eba05edebed44c4f986f49a5de55113
The next 32 bytes is the address parameter padded to with zeros.