Transactions – Who Pays Gas for Smart Contracts? Comprehensive Guide

contract-deploymentcontract-invocationfeesgastransactions

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!

Best Answer

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.

Related Topic