I'm trying to do something like this:
for (uint i = 0; i < reserves.length; i++) {
address resTok = reserves[i];
try IERC20Metadata(resTok).name() returns (string memory result) {
// import "hardhat/console.sol";
console.log("Reserve token name %d = %s", i, result);
}
catch {
console.log("Reserve token address %d = %s", i, resTok);
}
}
because sometimes reserves[i]
cannot cast to IERC20Metadata
so instead I just display the address.
Unfortunately, when the token cannot be casted to IERC20Metadata
I'm getting:
Error: Transaction reverted: function returned an unexpected amount of data
Instead of the try/catch catching the error... Any idea how I can achieve the same piece of code in a different way that works? Thanks!