viem-goviem-go

addChain

Adds an EVM chain to the wallet

Import

Import the wallet actions package so you can call this action.

import "github.com/ChefBingbong/viem-go/actions/wallet"

Usage

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() }()
err := wallet.AddChain(ctx, walletClient, wallet.AddChainParameters{
Chain: definitions.Optimism,
})
if err != nil {
log.Fatal(err)
}

Returns

error

Returns an error if the request fails.

Parameters

Configuration options accepted by this action.

Chain

  • Type: *chain.Chain

  • Required

The chain to add to the wallet.

import "github.com/ChefBingbong/viem-go/chain/definitions"
err := wallet.AddChain(ctx, walletClient, wallet.AddChainParameters{
Chain: definitions.Optimism,
})

JSON-RPC Method