Skip to content
On this page

watchAsset โ€‹

Requests that the user tracks the token in their wallet. Returns a boolean indicating if the token was successfully added.

Usage โ€‹

ts
import { walletClient } from './client'
 
const success = await walletClient.watchAsset({ 
  type: 'ERC20',
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18,
    symbol: 'WETH',
  },
})
ts
import { createWalletClient, custom } from 'viem'
import { mainnet } from 'viem/chains'

export const walletClient = createWalletClient({
  chain: mainnet,
  transport: custom(window.ethereum)
})

Returns โ€‹

boolean

Boolean indicating if the token was successfully added.

Parameters โ€‹

type โ€‹

  • Type: string

Token type.

ts
const success = await walletClient.watchAsset({
  type: 'ERC20', 
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18,
    symbol: 'WETH',
  },
});

options.address โ€‹

The address of the token contract.

ts
const success = await walletClient.watchAsset({
  type: 'ERC20',
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 
    decimals: 18,
    symbol: 'WETH',
  },
});

options.decimals โ€‹

  • Type: number

The number of token decimals.

ts
const success = await walletClient.watchAsset({
  type: 'ERC20',
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18, 
    symbol: 'WETH',
  },
});

options.symbol โ€‹

  • Type: string

A ticker symbol or shorthand, up to 11 characters.

ts
const success = await walletClient.watchAsset({
  type: 'ERC20',
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18
    symbol: 'WETH', 
  }
})

options.address โ€‹

  • Type: string

A string url of the token logo.

ts
const success = await walletClient.watchAsset({
  type: 'ERC20',
  options: {
    address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
    decimals: 18
    symbol: 'WETH',
    image: 'https://weth.com/icon.png', 
  }
})

JSON-RPC Methods โ€‹

eth_switchEthereumChain

Released under the MIT License.