0

I have a question about the ongoing cost of a smart contract.

Imagine a company named Acme Co. Acme Co deploys a smart contract the executes the following logic:

Pay Bob 10 ETH on the first of the month, every month.

It seems to me there must be ongoing behavior that uses computing resources. Thus, in addition to the transaction fee that's incurred to move ETH from ACME to Bob, it seems as if there must be some fee based cost to running the smart contract continuously.

If this is correct, then how are the fees around "the cost of compute" for figuring out its the first of the month and then executing the payment determined?

And to whom or what are those "operational fees" charged?

Thanks ins advance to an insight you can provide.

1 Answer 1

0

Pay Bob 10 ETH on the first of the month, every month.

The following logic cannot be executed by a smart contract. Something that could be done is

Pay Bob 10 ETH everytime a specific function is called, revert the transaction if the last successful payment has been made less than a month ago.

Smart contract cannot initiate transactions on their own, the fee incurred would be charged to the account calling the smart contract (and therefore initiating the payment), a fee breakdown would be a bit technical, as i believe you're not very familiar with the concept of smart contracts and how Ethereum works, but here's an overview :

  • a fixed 21000 gas for calling the contract

  • the cost of running the actual logic inside the smart contract, in a perfect world where you're making the contract by writing each opcode ( here's a list of all of them, an opcode is a "basic instruction", so to speak, it's the language a processor understands, they're not really clear and kinda hard to use to make complex programs, that's why we make higher level languages that look more like actual english, so it's easier to code, but those languages have to be translated to opcodes through an automated process done by a program called a "compiler", that process is more often than not less efficient than what you could do by hand) that cost would be very low, as all you need to do is

    • retreive the last time the contract was called (that's the SLOAD opcode, 2100 gas)
    • Check if it's been more than a month (for example, by substracting the current time and the time we just loaded from storage, and comparing that number with 2629746 (number of seconds in an average month) not gonna break down the opcodes here cause too lazy, but that'd be a few units of gas (10-20 probably)
    • Store the current time, overriding the previous one ( SSTORE, that'd be 20000 gas on the first time you do that, 2900 for every subsequent call (modifying a storage value from 0 to something is more expensive than if the current value is not 0)
  • Actually send the money to Bob (21000 gas again)

Hope this helps clearing up a bit how it all works :) if this is confusing or if you have any other question, feel free to ask

1
  • Thank you! @Foxxxey Jun 10, 2023 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.