watchAsset
Requests to watch an asset in wallet
Requests to watch an asset in wallet
Import the wallet actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/wallet"See how to construct a wallet client and call this action.
import ( "context" "log"
"github.com/ChefBingbong/viem-go/actions/wallet" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
walletClient, err := client.CreateWalletClient(client.WalletClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = walletClient.Close() }()
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", },})if err != nil { log.Fatal(err)}log.Printf("Asset added: %v", success)bool
Boolean indicating if the token was successfully added.
Configuration options accepted by this action.
Type: string
Required
The token type (e.g., "ERC20").
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", },})Type: WatchAssetOptions
Required
The token details.
Specify the token contract address for the asset to watch.
Type: string
Required
The address of the token contract.
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", },})Provide the symbol that will be shown for this token.
Type: string
Required
A ticker symbol or shorthand, up to 11 characters.
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", },})Define how many decimal places the token uses.
Type: uint8
Required
The number of token decimals.
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", },})Optionally supply a URL for the token logo.
Type: string
Optional
A string URL of the token logo.
success, err := wallet.WatchAsset(ctx, walletClient, wallet.WatchAssetParameters{ Type: "ERC20", Options: wallet.WatchAssetOptions{ Address: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", Decimals: 18, Symbol: "WETH", Image: "https://weth.com/icon.png", },})wallet_watchAsset (EIP-747)