Skip to content

WatchAsset

A token an app suggests a wallet track, for wallet_watchAsset (EIP-747).

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Wallet, type WatchAsset } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48");
const watch = Effect.gen(function* () {
// USDC on Ethereum mainnet
const asset: WatchAsset.WatchAsset = {
type: "ERC20",
options: { address: ADDRESS, symbol: "USDC", decimals: 6 },
};
return yield* Wallet.watchAsset(asset);
});
Schema Type Describes Used by
WatchAsset.schema WatchAsset.WatchAsset the token to watch Wallet.watchAsset
Field Type Notes
type string the standard the token implements: "ERC20", "ERC721", "ERC1155"
options object the fields below

options holds the token itself.

Field Type Notes
address Address the token contract, sent in its EIP-55 form
chainId number (optional) a JSON number, not a hex quantity. The wallet’s current chain when left out
symbol string (optional) for a fungible token
decimals number (optional) for a fungible token
image string (optional) the URL of the token’s logo, for a fungible token
tokenId string (optional) for an NFT
  • type decides the options. It is an open string. Beyond address, a wallet reads symbol, decimals and image for a fungible token, and tokenId for an NFT.
  • Checksummed on the wire. You give a lowercase Address.Address. The schema encodes it to its EIP-55 form, which the EIP requires and every address is written in, and decodes either form back to lowercase.
  • chainId is a JSON number. 1 is sent as 1. Unlike the chain ids of the other wallet types, it is not encoded as a hex quantity.

Encode one with the schema to see what is sent.

import { Effect, Schema } from "effect";
import { Address } from "@ethect/core";
import { WatchAsset } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
const wire = Effect.gen(function* () {
return yield* Schema.encodeEffect(WatchAsset.schema)({
type: "ERC20",
options: { address: ADDRESS, chainId: 1 },
});
// options.address is "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
});