[Ethereum] abi.decoder in solidity

abisolidityweb3js

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.

Best Answer

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));
 }
Related Topic