LogoLogo
  • Getting Started
    • Vanar
      • 🌐Overview
      • 🪙$VANRY Token
      • 🏛️The Vanar Foundation
    • Why Vanar?
      • 💡Our Philosophy
      • 🌍Green Chain
      • 🚀Fixed Fees
      • ⁉️Why L1?
      • 🏅Why Choose Vanar
      • ⭐Proof of Reputation
    • Vanar Architecture
      • Protocol Customizations
        • Native Gas Token ($VANRY)
        • Fixed Fees
        • Transaction Ordering
        • Block Rewards
        • Block Time
        • Block Size
      • EVM Compatibility
      • Consensus Mechanism
      • Fixed Fees
        • Gas Fees Tiers
        • How it works
        • Gas Price API
        • Fixed Fees Management
        • $VANRY Token Price API
  • Builders
    • For Developers
      • 🪐Vanar Network Details
      • ☑️Adding Network to Wallet
      • 🔗Connect Wallet to Vanar Chain
      • ⛽Gas Estimation
      • Build with thirdweb
        • Connect
        • Contracts
        • Engine
        • SDKs
      • Tutorials
        • Deploy a Token Contract - ERC20
        • Deploy an NFT Contract - ERC721
        • Deploy a Token Contract - ERC20 (Thirdweb)
        • Deploy an NFT Contract - ERC721 (Thirdweb)
    • Vanguard
      • Explorer
      • Faucet
      • Test $VG
  • Nodes and Validators
    • Staking
      • How To Stake
      • How To Unstake
      • How To Claim Rewards
    • Vanar Nodes
    • Setup a RPC Node
    • Setup a Validator Node
  • Tools
    • GroV
      • Frequently Asked Questions
  • White paper
  • vanarchain.com
Powered by GitBook
On this page
  • Estimate without gas limit
  • Estimate with gas limit
  1. Builders
  2. For Developers

Gas Estimation

PreviousConnect Wallet to Vanar ChainNextBuild with thirdweb

Vanar has a different gas fees structure to charge gas fees for transactions based on their transaction size. It is important for developers and end users (such as dApp users with Metamask wallet) to pass the right amount of gas when sending the transactions to the Vanar network.

The Vanar protocol by default estimates gas for the first tier (gas limit up to 12,000,000 gas) if no gas limit is provided when doing the gas estimation for a transaction. If a transaction is going to consume more than 12,000,000 gas then the gas estimation will fail if no gas limit is provided, as the default limit is set to 12,000,000.

You always get a working gas estimate if you pass the full block limit as gas limit (that is 30,000,000) when estimating the gas for a transaction. You can safely pass this estimated gas when sending the transaction to the network. Below are different scenarios of how this works:

Below is the sample code for gas estimation with library.

Estimate without gas limit

Below is sample code where gas is estimated without passing the gas limit.

const estimatedGas = await myContract.methods.methodToCall(parameters).estimateGas();
                                
console.log('Estimated gas is:', estimatedGas);

Possible results:

  1. It will estimate the gas correctly if the maximum gas required for the transaction will be less than 12,000,000 gas which is the max limit for tier 1 in Vanar protocol.

  2. It will return an error showing the gas required is exceeded the limit like:

    Error sending transactions: Error: Returned error: gas required exceeds allowance (12000000)

Estimate with gas limit

Below is sample code where gas is estimated by passing the gas limit for estimation.

const estimatedGas = await myContract.methods.methodToCall(parameters)
                                .estimateGas({gas: 30000000});
                                
console.log('Estimated gas is:', estimatedGas);

Possible results:

  1. It will estimate the gas correctly if the maximum gas required for the transaction will be less than the maximum block size which is 30,000,000 gas in Vanar protocol.

  2. It will throw an error showing the gas required is exceeded the limit like:

    Error sending transactions: Error: Returned error: gas required exceeds allowance (30000000)

Refer to the official to learn more about gas estimation in general.

⛽
web3.js
web3.js docs