6

I'm currently writing my first smart contract and I'm trying to figure out how to inject gas into the contract, of course, if it's possible.

I'm not sure If I got it correctly. With every transaction client pays the fee, in gas, and this gas will be used to execute called smart contract function.

In brief, I deploy the contract do I need to provide gas to it? Can I somehow force clients to do that? By the way, this.balance of contract is used as gas storage?

Cheers!

6

In brief, I deploy the contract do I need to provide gas to it? Can I somehow force clients to do that? By the way, this.balance of contract is used as gas storage?

When deploying what you have to pay is the fee of the transaction that was used to put the contract in the blockchain. Whenever someone wants to use your contract (invoke a function), he needs to send a transaction for that. And as you have correctly mentioned,

With every transaction client pays the fee, in gas, and this gas will be used to execute called smart contract function.

the one who send the transaction will have to pay the gas cost of executing that particular function in the contract.

You may refer this question as well.

Hope this helps!

EDIT - If it's a call for a constant function, view or pure, there won't be a transaction initiated, hence no gas cost. Check this for more on view and pure functions.

2

In addition to the correct answer, also note that calling constant functions do not cost any gas as they do not alter any storage variables.

  • +1 true that . worth mentioning, I'll update my answer as well – Achala Dissanayake Aug 20 '18 at 16:58

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.