How to Get a ERC20 Token Address via FewFactory

๐Ÿ“˜ Example Guide: How to Get an ERC20 Token Address via FewFactory

In Ring Swap, all tokens are wrapped using the Few Protocol and represented as FewTokens. However, there are cases where you may need to retrieve the original ERC20 token address from a given FewTokenโ€”such as when displaying token metadata, checking balances, or interacting with external protocols.

To support this, FewToken contracts expose a token() method that returns the original token address they wrap.

This allows seamless integration with systems that rely on standard ERC20 interfaces.


๐Ÿ” How to Retrieve the Original Token Address from a FewToken

๐Ÿ“˜ FewToken Interface

// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './IERC20.sol';

interface IFewERC20 is IERC20 {
    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}

๐Ÿ›  Example: Solidity Code to Query the Original ERC20 Token Address

๐Ÿงช Use Case: Displaying Token Metadata

Suppose youโ€™re building a dashboard that shows token symbols and decimals. You must first unwrap the FewToken to get its original ERC20 address, then use that to fetch metadata via standard ERC20 interfaces:

โœ… Summary

  • Use the token() method on a FewToken to get the underlying ERC20 token address.

  • This is useful for:

    • UI display (name, symbol, decimals)

    • Compatibility with other protocols

    • Balance checks or external API queries

Last updated