[Ethereum] Does ‘send’ with zero value cost gas

gassolidity

If a contract has a list of 100 addresses stored, and the code loops through the list and tries to send each address '0' ether. Does that generate 'gas' for each send call?

The reason I'm asking is because I saw some code that did this (loop through addresses and send '0' ether), and I was wondering if that could get more and more expensive the more addresses get added to the list. Thanks.

Best Answer

If you are performing these operation on the blockchain then yes. A contract = on the blockchain = the miners have to mine it and therefore you have to pay for those computations.

For this reason loops without limits are dangerous and should not be used, as you could accidentally have an endless loop and therefore an infinite amount of gas. Luckily, there is a global gas limit so your contract will fail (but the funds in the contract may be stuck, depending on the circumstances).

FYI, a standard transaction (one with no data) currently costs 21000 gas. If you just want to send a short message in the data, it would be maybe 22000 gas. But as the amount of data you send and the items in the contract increase, so do the transaction fees.

Regardless, unless you have a super crazy contract, these fees will be less that what traditional banking changes for a purchase / transaction ($0.10 + 3% on average). If you have said crazy contract, you should think about the design of the contract and potentially break it into pieces or change some computations to not be on the chain.

Related Topic