9

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!

0

3 Answers 3

10

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.

0
4

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
  • +1 true that . worth mentioning, I'll update my answer as well Commented Aug 20, 2018 at 16:58
0

In addition constant (view or pure) functions only cost gas if the constant (view or pure) function is executed or called by another external smart contract, that is not the owner of that function. But if it is called from within the smart contract that declared the constant (view or pure) function, then no gas will be used.

Just like when you use a class member function in another class in other programming languages by creating an object of that class. But in solidity this will cost you regardless of the fact that it's a constant function or not.

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.