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);});Schemas
Section titled “Schemas”| Schema | Type | Describes | Used by |
|---|---|---|---|
WatchAsset.schema |
WatchAsset.WatchAsset |
the token to watch | Wallet.watchAsset |
Fields
Section titled “Fields”| 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 |
Behavior
Section titled “Behavior”typedecides the options. It is an open string. Beyondaddress, a wallet readssymbol,decimalsandimagefor a fungible token, andtokenIdfor 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. chainIdis a JSON number.1is sent as1. 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"});