Value question I couldn't answer from a friend

PrimordialAAPrimordialAA Member Posts: 1
"I have a hard time figuring out how the value of ether makes sense. I need to study up on the details, but the abstract is you need ether to "execute code". So if ether is too highly priced, no one will use it to execute code, and if it's too low, then miners won't mine the contracts. So the amount of ether needed to execute a contract or part of a program seems like it needs to float. Not sure if they are accounting for this. This could be something like mining fees in some sense."


  • bochacobochaco ArgentinaMember Posts: 19
    I actually had the same question, i know there is a gas concept added but I'm not sure how these scenarios are handled really, in fact I don't know how to calculate the cost of executing a contract, not even in relative terms comparing different contracts. I'll be also interested in understanding this.
  • StephanTualStephanTual London, EnglandMember, Moderator Posts: 1,282 mod
    Here're a quick explanation on how gas work, albeit grossly oversimplified:

    Gas comes into play when you try to make a contract do something. You 'call' a function of the contract, which then executes that function. It could be validating an escrow, or 'like' a friend on a decentralized social app, or transfer an amount of contract specific metacoin to another user, etc. Anything.

    In order to execute this function, the contract needs gas, like your car needs fuel. This is measured in units of gas. So, as part of the function call, you specify how much 'gas' you want to send the contract, and how much you're willing to pay for that gas (priced in ether).

    The different operations a contract supports are priced differently. One execution cycle cost one gas for example. Others, like writing to storage, cost considerably more (because storage is a very scarce resource).

    If you send too much gas to the contract, and it doesn't use all of it, it is refunded to you. If you send too little, the contract stops and rolls back (kinda like your car when it's 'out of gas').

    How gas is priced depends on the global consensus of the community. It's likely the miners will be keen to execute operations that have the best priced gas first, and the rest later. This, in a sense, should be reminiscent of what you've seen with bitcoin transaction fees.

  • bochacobochaco ArgentinaMember Posts: 19
    So, is there/will there be a way to know what's the current gas price, perhaps by sensing the network, so my application/contract knows how much it needs to send in a transaction in order to have it processed?

    Also, if a malicious application/contract keeps sending transactions with little gas so the contract gets executed only partially, and by doing that it's wasting network's resources (let's say that waste is the kind of attack it is looking for). So in such a case I guess the quick answer is to penalize the sender by not getting a full refund of the gas sent.

    On the other hand, if it is not an attacker's application/contract, but it happens to just not know exactly what's the current consensus gas price (because I understand it would vary over the time) to successfully execute the contract it'll be penalized, perhaps unfairly, specially if it automatically re-tries several times to adjust the amount of gas to send.
    I might be really wrong on how I think all this but I really would like to hear what your thoughts/ideas are.

  • bochacobochaco ArgentinaMember Posts: 19
    I found another discussion thread where this is also being discussed:

    No final conclusions though...
  • avsaavsa Member Posts: 68 ✭✭
    One easy way to think about "Gas" is: the Ethereum community wants to build a giant, decentralized supercomputer in the cloud, and the only currency accepted for buying time on that machine is Ether.

    How much is the price of gas is not possible to know before we know the demand for decentralised computations and the supply of computers running it.

    AFAIK gas isn't refunded when the contract runs out, so if someone keeps creating contracts with not enough gas, he will be paying the bill.
  • bochacobochaco ArgentinaMember Posts: 19
    Ohh, I misunderstood, the refund only happens when you send more than needed, got it.
    The thing is that I need to dynamically know what the gas price is, because if I have a contract sending transactions I cannot adjust it manually but it has to realize itself over time...I guess :/
Sign In or Register to comment.