Connect 4337
Cometh ConnectCometh MarketplaceCometh Checkout
  • 🚀Quick start
    • What is Connect 4337
    • Getting started
    • Supported Networks
  • 🛠️CORE FEATURES
    • Create a Wallet
    • Send transactions
    • Go Gasless
    • Sign/Verify a message
    • Retrieve a wallet address
    • Handle owners
    • Import a safe into connect
  • 🥷ADVANCED
    • Session Keys
      • Tutorial
      • Policies
        • Sudo policy
        • Action policy
    • Social recovery
    • Add a passkey signer on a different OS
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
      • grantPermissions
    • Other signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
  • 🔌Integrations
    • React hooks
      • ConnectProvider
      • useAccount
      • useConnect
      • useDisconnect
      • useGetGasPrice
      • useSendTransaction
      • useSignMessage
      • useVerifyMessage
      • useWriteContract
      • Handle owners
        • useRemoveOwner
        • useValidateAddDevice
        • useCreateNewSigner
        • useAddOwner
        • useGetOwners/EnrichedOwners
      • Session Keys
        • useGrantPermission
        • useSendPermission
        • useSessionKeyClient
        • useSessionKeySigner
      • Recovery
        • useIsRecoveryActive
        • useSetUpRecovery
        • useGetRecoveryRequest
        • useCancelRecoveryRequest
    • Mobile SDKs
      • IOS
      • Android
      • React Native
    • Wagmi
  • SDK Core
    • Signers (Auth Providers)
      • EOA wallets (Metamask, Phantom...)
      • Magic signer
      • Web3Auth signer
      • Turnkey signer
      • Privy signer
    • Handle owners
    • Capabilities
      • sendCalls
      • getCallsStatus
      • getCapabilities
  • SDK Session Keys
    • Setup Smart Account Client
    • Manage session keys
    • Policies
      • Sudo policy
      • Action policy
  • 📦Bundler
    • Bundler API
      • eth_sendUserOperation
      • eth_estimateUserOperationGas
      • eth_getUserOperationByHash
      • eth_getUserOperationReceipt
      • eth_supportedEntryPoints
  • 💳Paymaster
    • Paymaster API
  • 📖RESOURCES
    • Migrate from the connect legacy SDK
    • Connect Legacy SDKs (Unity, JS)
    • FAQ
Powered by GitBook
On this page
  • Description
  • Parameters
  • Returns
  • Example
  • Usage context
  1. Integrations
  2. React hooks

useGetGasPrice

Description

This hook fetches the current gas price for transactions on the connected blockchain. It leverages a public client to estimate the gas fees and provides both maxFeePerGas and maxPriorityFeePerGas values.

The maxFeePerGas is calculated with a buffer, doubling the estimated fee to accommodate potential fluctuations in gas prices.

This hook is useful for determining the cost of transactions in real-time.

Parameters

  • rpcUrl? (string) : An optional RPC URL to use for the public client. If not provided, the default RPC URL associated with the smart account will be used.

Returns

  • data (GasPriceResult | undefined): The fetched gas price data, containing maxFeePerGas and maxPriorityFeePerGas.

  • isLoading (boolean): A boolean indicating whether the data is currently being fetched.

  • error (Error | null): An error object if an error occurred during the fetching process, otherwise null.

Example

import { useGetGasPrice } from "@cometh/connect-react-hooks";
import { formatEther } from "viem";
 
export const GasPriceDisplay = () => {
 const { data: gasPrice, isLoading, error } = useGetGasPrice();
 
 if (isLoading) return <p>Loading gas prices...</p>;
 if (error) return <p>Error fetching gas prices: {error.message}</p>;
 
 return (
   <div>
     <h2>Current Gas Prices</h2>
     <p>Max Fee Per Gas: {formatEther(gasPrice.maxFeePerGas)} ETH</p>
     <p>Max Priority Fee Per Gas: {formatEther(gasPrice.maxPriorityFeePerGas)} ETH</p>
   </div>
  );
};

Usage context

The useGetGasPrice hook must be used within a context that provides access to useSmartAccount. This ensures that the smartAccountClient and queryClient are available, and it avoids errors related to missing context or data.

PrevioususeDisconnectNextuseSendTransaction

Last updated 9 months ago

🔌