With solidity 5.0+ , the delegatecall function can return a boolean and a bytes representing return value. I want to understand how does one convert the returned bytes to various datatypes. ex
If the call is:
bool s, bytes b = delegatecall(....)
How can bytes b be converted to native types like (assuming i as the caller know the return value type):
- bytes32
- uint256
- user defined struct
Thanks!
Best Answer
You can use
abi.decode(...)
:Returning structs is not possible with the current ABI. You should add
pragma experimental ABIEncoderV2
to yourpragma
.Here you have a simple example to test:
Input:
Output: