0

In Solidity, I want users to provide the Solidity type of a response upfront, and when the response arrives, I want to decode it based on the type that the user provided - basically dynamic decoding of sorts.

You can imagine something like:

abi.decode(responseData, (userProvidedType));

Is there an elegant way of doing this?

1 Answer 1

0

unfortunately not. You usually have to have a giant if/else handler. You can also have different functions that take different types like hardhat's console (https://github.com/NomicFoundation/hardhat/blob/main/packages/hardhat-core/console.sol). eg:

function a(uint) {}

function a(address){}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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