2

I know that there is a calculation about how much gas a script consumes. My question is is this consumption per contract call (i.e. by an Ethereum client) or does it only apply when the contract is being deployed to the Ethereum network?

It makes more sense to me to the former where the cost is associated with every call because processing is involved, but I am not sure if that is economically feasible for the developers?

6

Both. All transactions on the network cost gas. Contract deployments often take much more than regular transaction calls to contracts, but some calls can be pretty expensive.

As for actual numbers, here are some.

Deployment: The large parts for contract deployments are

  1. Tx cost - 21k. This is for all transactions
  2. Contract creation cost - 32k. This is for the CREATE opcode and transactions with no "to" address, meaning they're contract creation
  3. Cost per byte of deployed code - 200. This is the cost of every byte of contract bytecode that is deployed. Minimizing this is usually how people minimize deployment costs.
  4. Constructor - Depends. This is the cost of the constructor, which is often basic code but also often has SSTORE opcodes, which is expensive.
  5. TX data - 64 bytes for non-zero and 4 bytes for zero. Every byte that is sent in tx data has these costs associated with it. This can be a decent amount for large contract deployments.

Contract calls: These are the costs for ops commonly used in contracts. There's a ton of different opcodes, so I'm just gonna list a few

  1. Addition/Subtraction/Pop/Push - 3. Pretty self explanatory.
  2. Multiply/Divide - 5. Also self explanatory.
  3. Call - 700. Cost of calls into other addresses (usually used for calling code or just sending eth.)

The rest of the opcode costs can be found on pages 24/25 of the yellow paper at https://ethereum.github.io/yellowpaper/paper.pdf.

1

Every transaction on the Ethereum network costs ETH (except for mined blocks of course).

Placing the contract on the network requires storage and calls to the contract that change state also cost eth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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