I'm using web3 to get the RLP encoded data for a function call like so

const safeTransferFrom: any = tokenERC1155Abi.find((f) => f.name === 'safeTransferFrom');
const params: Array<any> = [identity, minterAddr, 1, amount, '0x0'];
web3.eth.abi.encodeFunctionCall(safeTransferFrom, params);

is there a way to achieve the same result with the ethers.js library?

  • Nice i was looking for this – MadeInDreams Dec 11 '20 at 2:22

The equivalent in ethers.js involves first creating an "interface" object and calling a method on that:

> let ABI = [ "function transfer(address to, uint amount)" ];
> let iface = new ethers.utils.Interface(ABI);
> iface.encodeFunctionData("transfer", [ <function_params> ])

Taken from here

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.