I Would like to know if there is a solidity equivalent to this web3:


I'm currently looking at something like Seriality, but wondering if there was a supported native solidity implementation of the above. Including inline assembly.

My code looks something like: Web3 part:

var _data = await ABI.encode("120000000000000000000", user2, OCcontract1.address, "120000000000000000000", OCcontract2);
await swap(_data);

Solidity part:

     uint256 _amount;
     address _receiver;
     address _tokenLeadContract;
     uint256 _expectedAmount;
     address _expectedSC;

     (_amount, _receiver, _tokenLeadContract, _expectedAmount, _expectedSC) = decode(_data);

  • Can you please share your Solidity code, which requires such functionality? Feb 4 '19 at 12:29
  • Done, does this help at all? Feb 4 '19 at 14:15
  • Looks like you want to send 5 arguments of known types. So why do you need to encode these arguments on the client (web3) side to begin with, when you just send them "naturally". Feb 4 '19 at 16:08
  • Well we are going to be using _checkOnOCTReceived() which uses onER721Received() to determine whether we should call the function above, in order to comply with the stndard to the greatest extent possible we would like to use bytes memory _data, there is no real reason beyond this, but it would certainly look cleaner and be potentially more efficient. Feb 5 '19 at 10:39
  • And a lot less prone too accidentally sending incorrect input. Feb 5 '19 at 11:05

Yes, this is available in Solidity as abi.decode. You can see the documentation here https://solidity.readthedocs.io/en/v0.5.3/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions

For example, your code would look something like

 (_amount, _receiver, _tokenLeadContract, _expectedAmount, _expectedSC) = abi.decode(_data, (uint256, address, address, uint256, address));
  • does this exist in pragma 5.2? Feb 5 '19 at 15:12
  • Yes, it should work in > 5.1 Feb 5 '19 at 15:16
  • Works for <4 parameters at 5 it gives me an unknown compiler error Unknown exception during compilation it works when using the compiler for 5.3 perhaps a remix error? marking as correct regardless Feb 5 '19 at 15:44
  • Sounds like a compiler bug in 5.2, which got fixed in 5.3 Feb 5 '19 at 15:47

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.