viem
Version:
27 lines • 816 B
JavaScript
/**
* Returns the current price of gas (in wei).
*
* - Docs: https://viem.sh/docs/actions/public/getGasPrice
* - JSON-RPC Methods: [`eth_gasPrice`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gasprice)
*
* @param client - Client to use
* @returns The gas price (in wei). {@link GetGasPriceReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getGasPrice } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const gasPrice = await getGasPrice(client)
*/
export async function getGasPrice(client) {
const gasPrice = await client.request({
method: 'eth_gasPrice',
});
return BigInt(gasPrice);
}
//# sourceMappingURL=getGasPrice.js.map