getChainId
Returns the chain ID of the current network
Loading...
Returns the chain ID of the current network
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"An example showing how to construct a public client and query the current chain ID.
import ( "context" "log"
"github.com/ChefBingbong/viem-go/actions/public" "github.com/ChefBingbong/viem-go/client" "github.com/ChefBingbong/viem-go/client/transport" "github.com/ChefBingbong/viem-go/chain/definitions")
ctx := context.Background()
publicClient, err := client.CreatePublicClient(client.PublicClientConfig{ Chain: definitions.Mainnet, Transport: transport.HTTP("https://eth.llamarpc.com"),})if err != nil { log.Fatal(err)}defer func() { _ = publicClient.Close() }()
chainID, err := public.GetChainID(ctx, publicClient)if err != nil { log.Fatal(err)}log.Printf("Chain ID: %d", chainID)uint64
The chain ID of the current network.
This action takes no parameters.
Underlying JSON-RPC method used by this action.