0

Im trying to decode a bytes memory _data parameter directly in a smart contract.

Im currently running:

var data = await abi.encode("120000000000000000000", user2, OCcontract1.address, "120000000000000000000", OCcontract2);

So with its types

data abi.encode(BN, address, address,BN, address);

now within a function I want to use the solidity equivalent of abi.decode but running directly on the smart contract.

Any pointer will really help.

0

This did the trick for me:

functionName(data){
    uint _amount;
    address _receiver;
    address _tokenLeadContract;
    uint _expectedAmount;
    address _expectedSC;
    (_amount, _receiver, _tokenLeadContract, _expectedAmount, _expectedSC) = abi.decode(data, (uint, address, address, uint, address));
 }

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.