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

#include "HyperPlayUtils.h"
#include "Endpoints/RpcCall.h"

void OnRpcResponse(FString Response, int32 StatusCode)
{
    const bool bWasSuccessful = HyperPlayUtils::StatusCodeIsSuccess(StatusCode);

    UE_LOG(LogTemp, Display, TEXT("Rpc Personal Sign Success: %s"), bWasSuccessful ? "true" : "false");
    UE_LOG(LogTemp, Display, TEXT("Rpc Personal Sign Response: %s"), *Response);
}

int main(){
    const FString request("{\"method\": \"wallet_watchAsset\",\"params\": {\"type\": \"ERC20\",\"options\": {\"address\": \"0xdAC17F958D2ee523a2206206994597C13D831ec7\",\"symbol\": \"USDT\",\"decimals\": 6,\"image\": \"chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/images/contract/usdt.svg\"}}}")

    URpcCall* RpcCallInstance = URpcCall::RpcCall(nullptr,
        request,
        1);
    RpcCallInstance->GetOnCompletedDelegate().AddRaw(this, &OnRpcResponse);
    RpcCallInstance->Activate();
}

Response

true