1

I have this function:

/// @dev Checks if the type of asset-contract is same as the TokenType specified.
function _checkTokenType(Token memory _token) internal view {
    if (_token.tokenType == TokenType.ERC721) {
        try IERC165(_token.assetContract).supportsInterface(0x80ac58cd) returns (bool supported721) {
            require(supported721, "!TokenType");
        } catch {
            revert("!TokenType");
        }
    } else if (_token.tokenType == TokenType.ERC1155) {
        try IERC165(_token.assetContract).supportsInterface(0xd9b67a26) returns (bool supported1155) {
            require(supported1155, "!TokenType");
        } catch {
            revert("!TokenType");
        }
    } 
     else if (_token.tokenType == TokenType.ERC20) {
        if (_token.assetContract != CurrencyTransferLib.NATIVE_TOKEN) {
            try IERC165(_token.assetContract).supportsInterface(0x80ac58cd) returns (bool supported721) {
                require(!supported721, "!TokenType");
                try IERC165(_token.assetContract).supportsInterface(0xd9b67a26) returns (bool supported1155) {
                    require(!supported1155, "!TokenType");
                } catch Error(string memory) {}
            } catch Error(string memory) {}        
        }
    }
}

And I am testing it like this:

  describe("Loading", function () {
    describe("Co Allocated Smart Vault", function () {
      it("Owner should be able to load ERC20 to smart NFT", async function () {
        const { smartVault, owner } = await loadFixture(deploySmartVault);
        const { token } = await loadFixture(deployERC20Token)
        await smartVault.mintSmartNFT(owner.address);
        await token.approve(smartVault.address, ethers.BigNumber.from("1000000000000000"));
        await smartVault.loadTokens([[token.address,0,0,1000000000000000]], 0);
      });
    });
  });

But I am getting the following error:

Error: Transaction reverted without a reason string
      at SmartVault._checkTokenType (contracts/extension/TokenBundle.sol:142)
      at SmartVault._createBundle (contracts/extension/TokenBundle.sol:64)
      at SmartVault._storeTokens (contracts/extension/TokenStore.sol:47)
      at SmartVault.loadTokens (contracts/vault/SmartVault.sol:233)
      at <UnrecognizedContract>.<unknown> (0xb7f8bc63bbcad18155201308c8f3540b07f84f5e)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at HardhatNode._mineBlockWithPendingTxs (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1815:23)
      at HardhatNode.mineBlock (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:504:16)
      at EthModule._sendTransactionAndReturnHash (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1522:18)
      at HardhatNetworkProvider._sendWithLogging (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:139:22)
      at HardhatNetworkProvider.request (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:116:18)
      at JsonRpcHandler._handleRequest (/home/matifalcone/Blockchain/Polygon/SmartVault/node_modules/hardhat/src/internal/hardhat-network/jsonrpc/handler.ts:188:20)

Any thoughts?

2
  • Can you determine which line is reverting at?
    – Ismael
    Feb 27, 2023 at 6:34
  • Yes, it was reverting at the try IERC165(_token.assetContract).supportsInterface(0x80ac58cd) returns (bool supported721) line, for ERC20. This is because ERC20 does not implement ERC165. I have modified the smart contract so it does not revert if it is not able to instantiate an IERC165 for an ERC20 token contract. Feb 27, 2023 at 7:16

1 Answer 1

0

Finally, I was able to bypass this error by preventing my smart contract to revert.

ERC20 does not implement ERC165 by default. This means that the vast majority of tokens that interact with my contract would fail that validation.

This is the final code for the function _checkTokenType:

function _checkTokenType(Token memory _token) internal view {
    if (_token.tokenType == TokenType.ERC721) {
        try IERC165(_token.assetContract).supportsInterface(0x80ac58cd) returns (bool supported721) {
            require(supported721, "!TokenType");
        } catch {
            revert("!TokenType");
        }
    } else if (_token.tokenType == TokenType.ERC1155) {
        try IERC165(_token.assetContract).supportsInterface(0xd9b67a26) returns (bool supported1155) {
            require(supported1155, "!TokenType");
        } catch {
            revert("!TokenType");
        }
    } 
     else if (_token.tokenType == TokenType.ERC20) {
        if (_token.assetContract != CurrencyTransferLib.NATIVE_TOKEN) {
            try IERC165(_token.assetContract).supportsInterface(0x80ac58cd) returns (bool supported721) {
                require(!supported721, "!TokenType");
                try IERC165(_token.assetContract).supportsInterface(0xd9b67a26) returns (bool supported1155) {
                    require(!supported1155, "!TokenType");
                } catch (bytes memory) {}
            } catch (bytes memory) {}        
        }
    }
}

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.