RegisterToken

This function does not trigger any UI elements

Description

Function to register any asset that is not supported by default. The token will then be supported throughout the wallet - eg. it will be shown on balances page if the user has a non-zero balance of the token.

Details

Only ERC20 tokens following the OpenZeppelin standard are supported for now

Signature

RegisterToken(name, symbol, chain, image, contractAddress, decimal)

Arguments

Return Value

Instance of the new Asset

Example

First, create an instance of the token by calling RegisterToken:

custom-tokens.js
import { RegisterToken, chains } from '@metafi/metafi-react-package';

export const WETH = RegisterToken(
    'Goerli Wrapped Ethereum', 
    'WETH', 
    chains.goerli,
    'https://d2qdyxy3mxzsfv.cloudfront.net/images/logo/ethereum.png',  
    '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
    18, 
)

Then, pass in the custom token(s) you have created while initializing the MetafiProvider:

App.js
import { MetafiProvider, chains } from '@metafi/metafi-react-package';
import { WETH } from './constants/custom-token.js';

function App() {
    return (
    <MetafiProvider
        apiKey={"YOUR_API_KEY"}
        secretKey={"YOUR_SECRET_KEY"}
        supportedChains={[chains.eth, chains.goerli]}
        customTokens={[WETH]}
        options={}
    >
        <YourComponents>
        ...
        </YourComponents>
    </MetafiProvider>
    );
};

And voila! Your token will now be accessible throughout the wallet.

Last updated