Giter VIP home page Giter VIP logo

Comments (7)

hanjukim avatar hanjukim commented on August 29, 2024

Where did you get uusd gas price for 2?

from terra.js.

jimryan avatar jimryan commented on August 29, 2024

I'm curious about this too. I see other projects hardcoding gas prices (including terra.js which hardcodes default uluna gas prices). For example, it seems common to hardcode the uusd gas price to 0.15.

I've been doing something like this with success:

const stdTx = new StdTx([msg], new StdFee(0), [])
const fee = await terraClient.tx.estimateFee(stdTx, { gasPrices: { uusd: 0.15 } });

But that's including a hardcoded uusd gas price. That successfully calculates the stability fee and total gas, though, and ultimately works (at least on localterra and tequila), but is that the "correct" way to calculate fees? Is there a better way to estimate the gas price/ask the node for an acceptable gas price?

from terra.js.

hanjukim avatar hanjukim commented on August 29, 2024

@jimryan There are several correct ways to put fees

Given that the recommended gas prices (could be queried from https://fcd.terra.dev/v1/txs/gas_prices for the mainnet) does not change often, I personally prefer to use static StdFee when I create predictable transactions. By the meaning of predictable is the gas of the transaction doesn't change much by variables. I prefer this way to minimize network round trips.

In detail, when you call the create function without the fee parameter it automatically calls estimateFee function with default gas prices which doesn't have other gas prices than "uluna" which is not what you probably want.

If you want it to estimate fee every time when you create the StdSignMsg put recommended gasPrices (and feeDenoms) when you either create the LCDClient object or create StdSignMsg

from terra.js.

jimryan avatar jimryan commented on August 29, 2024

@hanjukim Thanks! I ended up configuring the client with a hardcoded uusd gas price, like this:

new LCDClient({
  URL: network.lcdURL,
  chainID: network.chainID,
  gasPrices: network.gasPrices
});

Where network.gasPrices is: { uusd: 0.15 }.

Then I estimateFee manually (so we can perform a balance check and it could be displayed to the user), and then post the message and the fee to the Extension.

It sounds like the only way to improve on that would be to query the current uusd gas price from the /gas_prices endpoint, right?

from terra.js.

nocmar avatar nocmar commented on August 29, 2024

If I not specify gasPrices in LCD client for uusd so default for tequila-4 is just {uluna: 0.15} I won't get valid fee from estimateFee or create for feeDenoms: ["uusd"] right?

from terra.js.

hanjukim avatar hanjukim commented on August 29, 2024

Check out #107 I think this will resolve the issue?

from terra.js.

xcsob avatar xcsob commented on August 29, 2024

@hanjukim Thanks! I ended up configuring the client with a hardcoded uusd gas price, like this:

new LCDClient({
  URL: network.lcdURL,
  chainID: network.chainID,
  gasPrices: network.gasPrices
});

Where network.gasPrices is: { uusd: 0.15 }.

Then I estimateFee manually (so we can perform a balance check and it could be displayed to the user), and then post the message and the fee to the Extension.

It sounds like the only way to improve on that would be to query the current uusd gas price from the /gas_prices endpoint, right?

Can you show me the way you estimate fee? I'm trying with the method, but I'm getting the following error:

Possible Unhandled Promise Rejection (id: 18):
TypeError: Cannot read property 'map' of undefined
TypeError: Cannot read property 'map' of undefined
    at TxBody.toProto (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:270293:33)
    at Tx.toProto (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:270200:25)
    at Tx.toBytes (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:270209:109)
    at TxAPI.encode (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:316578:29)
    at TxAPI.<anonymous> (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:316544:32)
    at step (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:316312:21)
    at Object.next (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:316242:16)
    at /Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:316214:69
    at tryCallTwo (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:31031:7)
    at doResolve (/Users/user/Desktop/Project_2/Project/.vscode/.react/index.bundle:31195:15)

The code I'm using:

const signerData = [{sequenceNumber: wallet.key.sequenceNumber,
        publicKey: wallet.key.publicKey}]
        // estimate the fee
        const fee = await this.terra.tx.estimateFee(
            signerData,
            msgs,
            {gasPrices: { uusd: 0.15 }}
        );

This is the version of terra.js I have:
"@terra-money/terra.js": "^3.0.0",

from terra.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.