TronLink Docs
Homepage
  • Introduction
  • HD Wallets
  • TronLink App
    • Asset Management
      • Custom Token
    • DeepLink
      • Open Wallet
      • Open DApp
      • Login by TronLink
      • Transfer
      • Sign Transaction
      • Sign Message
      • Result Code
    • DApp Support
      • TronLink Integration
      • DApp Explorer
  • TronLink Wallet Extension
    • Request TronLink Extension
      • Connect Website
      • Add Token
    • Receive messages from TronLink
      • Account Change Message
      • Network Change Message
      • Successful connection message
      • Disconnect website message
      • Messages to Be Deprecated
        • User rejects connection
        • User disconnects from the website
        • User accepts connection
        • User requests to connect to the website
  • DApp
    • Start Developing
    • Multi-Signature Transfer
    • Message Signature
    • General Transfer
    • Stake2.0
Powered by GitBook
On this page
  1. TronLink Wallet Extension
  2. Request TronLink Extension

Add Token

Overview

Buttons on DApps allow users to directly add the specified tokens to the asset list on their TronLink user extension.

Specification

Example

const res = await tronWeb.request({
  method: 'wallet_watchAsset',
  params: {
    type: 'TRC20',
    options: {
      address: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
    }
  },
});

Parameters

interface WatchAssetParams {
  type: 'trc10' | 'trc20' | 'trc721';
  options: {
    address: string;
    symbol?: string;
    decimals?: number;
    image?: string;
  }
}
  • method: wallet_watchAsset fixed string

  • params: WatchAssetParams, the specific parameters are as follows:

    • type: Only 'trc10', 'trc20', 'trc721' are supported now

    • options:

      • address: the contract address of the token or the token id, required

      • symbol: placeholder (currently unused), optional

      • decimals: placeholder (currently unused), optional

      • image: placeholder (currently unused), optional

Returns

This method has no return value

Interaction

Add TRC10 assets

if (window.tronLink.ready) {
  const tronweb = tronLink.tronWeb;
  try {
    tronweb.request({
      method: 'wallet_watchAsset',
      params: {
        type: 'trc10',
        options: {
          address: '1002000'
        },
      },
    });
  } catch (e) {}
}

After clicking "Add", users can see the added assets as shown in the following screen:

Add TRC20 assets

if (window.tronLink.ready) {
  const tronweb = tronLink.tronWeb;
  try {
    tronweb.request({
      method: 'wallet_watchAsset',
      params: {
        type: 'trc20',
        options: {
          address: 'TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3'
        },
      },
    });
  } catch (e) {}
}

Add TRC721 asset

if (window.tronLink.ready) {
  const tronweb = tronLink.tronWeb;
  try {
    tronweb.request({
      method: 'wallet_watchAsset',
      params: {
        type: 'trc721',
        options: {
          address: 'TVtaUnsgKXhTfqSFRnHCsSXzPiXmm53nZt'
        },
      },
    });
  } catch (e) {}
}
PreviousConnect WebsiteNextReceive messages from TronLink

Last updated 2 years ago

When the code is executed, a TronLink pop-up window for adding TRC10 assets will show up, and the user can click “Add” or “Cancel”.

When the code is executed, a TronLink pop-up window for adding TRC20 assets will show up, and the user can click “Add” or “Cancel”.

After clicking “Add”, users can see the added assets as shown in the following screen:

When the code is executed, a TronLink pop-up window for adding TRC721 will show up, and the user can click “Add” or “Cancel”.

After clicking “Add”, users can see the added assets as shown in the following screen: