getGasPrice
Returns the current price of gas in wei
Loading...
Returns the current price of gas in wei
Import the public actions package so you can call this action.
import "github.com/ChefBingbong/viem-go/actions/public"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())*big.Int
The current gas price in wei.
This action takes no parameters.
Underlying JSON-RPC method used by this action.