-
Notifications
You must be signed in to change notification settings - Fork 447
docs: add auth/gasprice query and gas price mechanism #4995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8712dd3
af2751f
134decb
527c5d1
8ad6f63
5a327a0
a83e38e
c2e8b5f
3c499fa
0c3dd22
1dff049
55ede4f
262608d
ef0dc37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,67 @@ Maximum Fee = Gas Wanted × Gas Fee | |
|
|
||
| You will be charged the gas fee you specified. | ||
|
|
||
| ## Gas Price | ||
|
|
||
| The network dynamically adjusts the minimum required gas price after each block | ||
| based on demand. This ensures the network responds to congestion by increasing | ||
| prices when usage is high and decreasing them when usage is low. | ||
|
|
||
| ### How Gas Price Works | ||
|
|
||
| The gas price is returned as a `GasPrice` object with two fields: | ||
| - `gas` - the gas units (e.g., 1000) | ||
| - `price` - the price for those gas units (e.g., "100ugnot") | ||
|
|
||
| Together, these represent a **rate**. For example, `{gas: 1000, price: "100ugnot"}` | ||
| means the minimum rate is 100 ugnot per 1000 gas units, which simplifies to | ||
| 0.1 ugnot per gas unit. | ||
|
|
||
| ### Calculating Your Gas Fee | ||
|
|
||
| Your `--gas-fee` must meet or exceed this network gas price for your transaction | ||
| to be accepted. To calculate the minimum fee: | ||
|
|
||
| 1. Query the current gas price | ||
| 2. Calculate the rate: `price / gas` | ||
| 3. Multiply by your `--gas-wanted` | ||
|
|
||
| **Example:** | ||
| ```bash | ||
| # Query returns: {gas: 1000, price: "100ugnot"} | ||
| # Rate = 100 ÷ 1000 = 0.1 ugnot/gas | ||
|
|
||
| # If you want --gas-wanted 2000000: | ||
| # Minimum fee = 2,000,000 × 0.1 = 200,000 ugnot | ||
| # So set: --gas-fee 200000ugnot (or higher) | ||
| ``` | ||
|
|
||
| ### Querying Gas Price | ||
|
|
||
| You can query the current network gas price using: | ||
| ```bash | ||
| gnokey query auth/gasprice -remote https://rpc.gno.land:443 | ||
| ``` | ||
|
|
||
| This returns the gas price calculated from the most recently completed block, | ||
| which is the minimum rate currently required for new transactions. | ||
|
|
||
| For more details, see [`auth/gasprice`](../users/interact-with-gnokey.md#authgasprice). | ||
|
|
||
| ### How the Network Adjusts Gas Price | ||
|
|
||
| The network automatically adjusts the gas price after each block based on demand: | ||
|
|
||
| - **Low demand**: Price decreases (but never below 1 ugnot/1000 gas) | ||
| - **High demand**: Price increases | ||
|
|
||
| The network targets 70% utilization of the maximum block gas limit (3B gas) by default. | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there's, add a link to current value on-chain |
||
| When blocks exceed this target, prices rise. When blocks fall below it, prices drop. | ||
| Changes are gradual to avoid sudden price spikes. | ||
|
|
||
| **Note**: Individual validators can also set their own minimum gas price through the | ||
| `min_gas_prices` configuration parameter in their `config.toml` file. Different validators may have different minimums. | ||
|
|
||
| ## Typical Gas Values | ||
|
|
||
| Here are some recommended gas values for common operations: | ||
|
|
@@ -99,6 +160,15 @@ gnokey maketx call \ | |
| YOUR_KEY_NAME | ||
| ``` | ||
|
|
||
| ## Common Errors | ||
|
|
||
| **Insufficient fees:** `insufficient fees; got: 50000ugnot required: 200000ugnot` | ||
| - Your `--gas-fee` is too low. Increase it to meet the minimum required. | ||
|
|
||
| **Out of gas:** `out of gas in location: ... wanted: 100000, used: 150000` | ||
| - Your `--gas-wanted` is too low. Use `--simulate only` to estimate needed gas, then increase. | ||
| - ⚠️ **You're still charged for failed transactions!** Fees are deducted before execution, so even if your transaction runs out of gas, you pay for the gas consumed up to the limit. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would specify, though, that This means that if the transaction fails during simulation with an out of gas error, the user won't be charged (because the transaction isn't submitted to the blockchain in the first place, only to the rpc node). This doesn't mean that the user is never charged with |
||
|
|
||
| ## Gas Optimization Tips | ||
|
|
||
| To minimize gas costs, consider these optimization strategies: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be a good idea to calculate that rate automatically when calling auth/gasprice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably can't do that in gnokey, but we can make a small util with
sedandjq:gnokey query auth/gasprice -remote https://rpc.gno.land:443 \ | sed '1d; s/^data: //' \ | jq -r '(.gas | tonumber) as $gas_val | (.price | capture("^(?<amount>[0-9]+)(?<denom>.*)$")) | "\((.amount | tonumber) / $gas_val) \(.denom)/gas\n\($gas_val / (.amount | tonumber)) gas/\(.denom)"'Outputs: