For the complete documentation index, see llms.txt. This page is also available as Markdown.

Add Token

Request

This method allows developers to add a custom token to the token list of a MetaMask or WalletConnect wallet. This method is important to game developers, because many games have dozens or even hundreds of tokens, spanning beyond the list of tokens that MetaMask or other wallets are able to auto-detect.

Parameters

  • type : In the future, other standards will be supported

  • address : The address of the token contract

  • symbol: A ticker symbol or shorthand, up to 11 characters

  • decimals: The number of token decimals

  • image: A string url of the token logo

curl --location --request POST "localhost:9680/rpc" \
--header 'Content-Type: application/json' \
--data-raw '{
   "request":{
        "method": "wallet_watchAsset",
        "params": {
            "type": "ERC20",
            "options": {
                "address": "0xdAC17F958D2ee523a2206206994597C13D831ec7",
                "symbol": "USDT",
                "decimals": 6,
                "image": "chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/images/contract/usdt.svg"
            }
        }
   },
   "chain":{
      "chainId":"1"
   }
}'
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class AddToken : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(Add());
    }

    private IEnumerator Add()
    {
        string jsonString = "{ \"request\":{ \"method\": \"wallet_watchAsset\", \"params\": { \"type\": \"ERC20\", \"options\": { \"address\": \"0xdAC17F958D2ee523a2206206994597C13D831ec7\", \"symbol\": \"USDT\", \"decimals\": 6, \"image\": \"chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/images/contract/usdt.svg\" } } }, \"chain\":{ \"chainId\":\"1\" } }";
        byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

        UnityWebRequest request = new UnityWebRequest("localhost:9680/rpc", "POST");
        request.uploadHandler = new UploadHandlerRaw(jsonBytes);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");

        yield return request.SendWebRequest();
        Debug.Log(request.error);
        Debug.Log(request.downloadHandler.text);
    }
}

If you have the HyperPlay plugin installed, copy and paste the following into a Blueprint Graph.

Response

Errors will have an HTTP response status 500-599

Last updated