viem-goviem-go

getGasPrice

Returns the current price of gas in wei

Import

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

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

Usage

A minimal example showing how to construct a public client and fetch the current gas price.

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() }()
gasPrice, err := public.GetGasPrice(ctx, publicClient)
if err != nil {
log.Fatal(err)
}
log.Printf("Gas price: %s wei", gasPrice.String())

Returns

*big.Int

The current gas price in wei.

Parameters

This action takes no parameters.

JSON-RPC Method

Underlying JSON-RPC method used by this action.

eth_gasPrice