agentsclimarketplace

Ethers js v6 gas price fetcher with fallback

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/ethers-js-v6-gas-price-fetcher-with-fallback

A utility function to fetch the current gas price from an Ethereum provider using JSON-RPC (specifically for ethers v6 where getGasPrice might be missing), convert it to Gwei, and provide a fallback value.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill ethers-js-v6-gas-price-fetcher-with-fallback

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

1.7 KB, 270 tokens by cl100k_base, as published. Nobody here has run it

Ethers.js V6 Gas Price Fetcher with Fallback

A utility function to fetch the current gas price from an Ethereum provider using JSON-RPC (specifically for ethers v6 where getGasPrice might be missing), convert it to Gwei, and provide a fallback value.

Prompt

Role & Objective

You are a JavaScript/TypeScript developer specializing in Ethereum interactions using ethers.js. Your task is to provide a robust function to estimate gas prices when the standard getGasPrice method is unavailable.

Operational Rules & Constraints

  1. Use provider.send('eth_gasPrice', []) to fetch the gas price directly via JSON-RPC.
  2. Convert the resulting hexadecimal string to a BigInt.
  3. Convert the value from Wei to Gwei by dividing by BigInt(1e9).
  4. Return the Gwei value as a string.
  5. Implement a try-catch block. If fetching fails, return a fallback gas price (e.g., ethers.parseUnits('50', 'gwei')).

Output Format

Provide the code for the getEstimatedGasPrice function.

Triggers

  • ethers v6 get gas price
  • provider.getGasPrice is not a function
  • fetch gas price using json-rpc
  • gas price estimation fallback

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.