2

I read that there is a cost that should be paid when deploying a smart contact to the etherum. Is there is a cost for an end user to interact with a certain smart contact ?? For example : if I build a contract for a renting company , id end users who are looking for certain rental offers who need to interact with that contact, do they need to pay ethers ??

And if yes, that not make sense to let users who need to use smart contact to pay fees. How it can be avoided ??

marked as duplicate by Achala Dissanayake, Richard Horrocks, eth Aug 26 '18 at 5:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

All interactions between users and smart contracts happen through transactions.

Every transactions has a cost, which is measured in two parts:

  • Gas: a fee dependent on the complexity of the transaction and the operations incurred by the transaction
  • Gas Price: A conversion between Gas and Ether, measured in ether/gas

Thus you can see that all transactions require some amount of ether to complete. This system is in place to prevent denial of service attacks, infinite loops, and other resource heavy computations.

In general, there is no way to avoid paying these fees per transaction. There are systems you can set up where if you want your customers to not pay fees, you can pay for fees on behalf of the user. But these systems go around the underlying authentication processes in place for Ethereum, and require you to own a service which has a high trust with a smart contract.

You can learn more here: Transactions

0

Ethereum uses the "Ethereum Virtual Machine (EVM)" to execute the code of smart contracts. This EVM is quasi-turing complete. A machine is turing complete when it is able to solve any calculable problem given enough space and time. But why is it only "quasi" turing complete? Because besides enough space and time, the EVM requires enough GAS (Ether). Every instruction, besides the instructions STOP, RETURN and REVERT, requires GAS to be executed in the EVM. Example: If you want to add two values from memory you have to pay 3 GAS for the addition. You can inform yourself about the cost per instruction in the yellowpaper, Appendix G and H (https://ethereum.github.io/yellowpaper/paper.pdf). If a user wants to execute a smart contract and sends a transaction to the ethereum network that contains the order to do so, the user has to pay gas. So to answer your first question, every user has to pay gas if they send an order to execute a smart contract via a transaction. Nevertheless, there is a special case. If you only want to read data using a smart contract, so that you don't change the state of the storage, you can do so without paying gas. This is achieved by running the EVM and executing the smart contract only locally on your computer (or any other computer which offers this service).

How can you avoid this? If you want to protect the users of your smart contract from paying those costs, you have to take the gas from another source. This means that you or somebody else has to pay the gas for the user before they use the smart contract. For example, you could put 1 ether into your smart contract to cover those costs. This is risky though, since you have to protect your smart contract from a "ddos" attack which consumes all the ether you have reserved for gas. Further, you have to watch that you smart contract does not run out of gas for your users, otherwise your services will be unavailable for the users and they are losing their money they have to pay to call your smart contract (every transaction costs 21000 GAS at least).

  • According to your Answer " If you only want to read data using a smart contract without paying gas, That could by running the EVM and executing the smart contract only locally on your computer (or a computer which offers this service). Does the end users who query the smart contract for certain info. should be a part of the Etherum network? Consider this scenario, If you need to build a smart contract that has some data, and there are IoT devices (may reach millions of nodes) wanna query that contract to check this values, How we can avoid that these nodes avoid paying for gas? – Mohamed Aug 24 '18 at 1:34
  • @Mohamed : The problem can be solved by introducing your own full node and querying it by your iot devices. Example: Setup a geth node using the "--rpc" flag. This node has to sync the complete blockchain, so make sure there is enough persistent memory available. Use the JSON-RPC api to be able to send remote procedure calls (rpc) to your geth node (github.com/ethereum/wiki/wiki/JSON-RPC#json-rpc-api). The call you are looking for should be eth_call. This way, your iot devices can send a json rpc to your node which then executes the smart contract which queries the data. – sea212 Aug 24 '18 at 13:40
  • the solution you said return me back to the client-server model, so if the server node you said is off, all the IoT devices cannot query the contract. How can I avoid using a server as a node in the Blockchain. I want the system to be completely distributed – Mohamed Aug 24 '18 at 22:42

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