Given a function setXY(uint256 x, uint256 y)
, how can I encode data parameters x
and y
into a single bytes data
array that can be fed into abi.encodeWithSignature('setXY(uint256,uint256)', data)
?
Ethers has an ABI encoder that allows for encoding array values according to array types. This allows encoding parameters via abiCoder.encode(['uint256', 'uint256'], ['1', '2'])
into a bytes
array.
But, feeding this as data
into abi.encodeWithSignature
or abi.encodeWithSelector
results in data
being read incorrectly, likely due to abi.encode
leaving leading zeros for each argument.
Is there any way of accomplishing this correctly?