Connect DApp to OKX Wallet
Display tokens

Display tokens#

When users open OKX Wallet, they're shown a variety of assets, including tokens. By default, OKX Wallet detects mainstream tokens and displays them. However, for most tokens, users will need to add the tokens themselves.

While this is possible using our UI with the Add Token button, it can be cumbersome, and more prone to error since it involves the process of users interacting with contract addresses. It can greatly improve security and user experience for adding tokens to OKX Wallet by taking advantage of the wallet_watchAsset API as defined in EIP-747.

Example#

If you'd like to integrate token suggestions into your own web app, you can follow this code snippet:

const tokenAddress = '0xd00981105e61274c8a5cd5a88fe7e037d935b513';
const tokenSymbol = 'TUT';
const tokenDecimals = 18;
const tokenImage = 'http://placekitten.com/200/300';
try {
  // wasAdded is a boolean. Like any RPC method, an error may be thrown.
  const wasAdded = await okxwallet.request({
    method: 'wallet_watchAsset',
    params: {
      type: 'ERC20', // Initially only supports ERC20, but eventually more!
      options: {
        address: tokenAddress, // The address that the token is at.
        symbol: tokenSymbol, // A ticker symbol or shorthand, up to 5 chars.
        decimals: tokenDecimals, // The number of decimals in the token
        image: tokenImage, // A string url of the token logo
      },
    },
  });

  if (wasAdded) {
    console.log('Thanks for your interest!');
  } else {
    console.log('Your loss!');
  }
} catch (error) {
  console.log(error);
}

Here are a couple live web applications that let you enter token details, and then share them with a simple web link: