RegisterToken

Description

Function to register any asset that is not supported by default. The token will then be supported throughout the SDK - eg. it will be returned in the assets field of the RetrieveUser function if the user has a non-zero balance of the token.

Please note that by default, we support native tokens that have been outlined in Assets.

Details

Signature

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

Arguments

Return Value

Instance of the new Asset

Example

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

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

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

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

App.js
import { 
    TransferTokens,
} from '@metafi/metafi-js-package';
import { WETH } from "./tokens/custom-token.js";

function App() {
    const transferWETH = () => {
        TransferTokens({
                to: "0xd4594dECd0ed8BA4C7d5810dbB8D004C74250BD5",
                amount: "1",
                currency: WETH,
                callback: (result) => {
                    console.log("callback result", result);
                },
            },
            "YOUR-API-KEY"
        );
    }
    
    return (
        <div>
	    <button onClick={transferWETH}>Transfer 1 WETH</button>
        </div>
    );
}

export default App;

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

Last updated