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.


This did the trick for me:

    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 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.