Links

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

Parameter
Type
Definition
name
String
Name of the currency, eg. "USD Coin"
symbol
String
Symbol for the currency, eg. "USDC"
chain
String
Chain on which the contract is deployed. eg. for USDC on ETH, pass in chains.eth
image
String
Link to png image of the token. Max size is 50KB
contractAddress
String
Contract address of the ERC20 token, eg. for USDC on ETH, it is 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
decimal
Number
Number of decimal places of precision for the asset. eg. 18 for ETH
tokenStandard
Object
Specify the token standard. eg:
{
"name": "erc20",
}

Return Value

Instance of the new Asset

Example

First, create an instance of the token by calling RegisterToken:
custom-token.js
1
import { RegisterToken, chains } from '@metafi/metafi-js-package';
2
3
export const WETH = RegisterToken(
4
'Goerli Wrapped Ethereum',
5
'WETH',
6
chains.goerli,
7
'https://d2qdyxy3mxzsfv.cloudfront.net/images/logo/ethereum.png',
8
'0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
9
18,
10
{
11
"name": "erc20",
12
}
13
)
14
Then, pass in the custom token(s) you have created while initializing the MetafiProvider:
App.js
1
import {
2
TransferTokens,
3
} from '@metafi/metafi-js-package';
4
import { WETH } from "./tokens/custom-token.js";
5
6
function App() {
7
const transferWETH = () => {
8
TransferTokens({
9
to: "0xd4594dECd0ed8BA4C7d5810dbB8D004C74250BD5",
10
amount: "1",
11
currency: WETH,
12
callback: (result) => {
13
console.log("callback result", result);
14
},
15
},
16
"YOUR-API-KEY"
17
);
18
}
19
20
return (
21
<div>
22
<button onClick={transferWETH}>Transfer 1 WETH</button>
23
</div>
24
);
25
}
26
27
export default App;
28
And voila! Your token will now be accessible throughout the wallet.