Skip to content

watchAsset

Action for requesting user tracks the token in their wallet. Returns a boolean indicating if the token was successfully added.

Import

ts
import { watchAsset } from '@wagmi/core'

Usage

ts
import { watchAsset } from '@wagmi/core'
import { config } from './config'

await watchAsset(config, {
  type: 'ERC20',
  options: {
    address: '0x0000000000000000000000000000000000000000',
    symbol: 'WAGMI',
    decimals: 18,
  },
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters

ts
import { type WatchAssetParameters } from '@wagmi/core'

connector

Connector | undefined

Connector to sign message with.

ts
import { getAccount, watchAsset } from '@wagmi/core'
import { config } from './config'

const { connector } = getAccount(config)
const result = await watchAsset(config, {
  connector, 
  options: {
    address: '0x0000000000000000000000000000000000000000',
    symbol: 'WAGMI',
    decimals: 18,
  },
  type: 'ERC20',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

options

{ address: string; symbol: string; decimals: number; image?: string | undefined; }

Asset options.

ts
import { watchAsset } from '@wagmi/core'
import { config } from './config'

const result = await watchAsset(config, {
  options: { 
    address: '0x0000000000000000000000000000000000000000', 
    symbol: 'WAGMI', 
    decimals: 18, 
  }, 
  type: 'ERC20',
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

type

'ERC20'

Type of asset.

ts
import { watchAsset } from '@wagmi/core'
import { config } from './config'

const result = await watchAsset(config, {
  options: {
    address: '0x0000000000000000000000000000000000000000',
    symbol: 'WAGMI',
    decimals: 18,
  },
  type: 'ERC20', 
})
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Return Type

ts
import { type WatchAssetReturnType } from '@wagmi/core'

boolean

Returns a boolean indicating if the token was successfully added.

Error

ts
import { type WatchAssetErrorType } from '@wagmi/core'

TanStack Query

ts
import {
  type WatchAssetData,
  type WatchAssetVariables,
  type WatchAssetMutate,
  type WatchAssetMutateAsync,
  watchAssetMutationOptions,
} from '@wagmi/core/query'

Viem

Released under the MIT License.