Transaction vs Call
Last updated
Last updated
There are two ways we can invoke functions.
Call
Send a transaction (data modification)
A transaction is necessary, if a value in a Smart Contract needs to be updated (state change).
A call is done, if a value is read.
Transactions cost Ether (gas), need to be mined and therefore take a while until the value is reflected, which you will see later. Calls are virtually free and instant.
Anytime we send a transaction to the network it takes time to be process (it must be confirmed by other nodes and mined).
When we send a transaction to a function, we are returned a transaction hash that identifies the transaction.
We do not get a return value back, even if the function has a return component in it.
Costs money.
Transactions always start with an externally owned account signing a transaction and submitting it to the network. The returned value is a transaction receipt.
The outcome of the transaction is unknown because nothing has happened yet except that a request has been submitted to the network for verification in the future.
A typical approach to coping with this fact of life is to wait for the transaction to be mined, then inspect the transaction log for useful output, inspect the success/fail status and draw your own conclusions, or inspect a read-only function to discover the new state after the transaction was mined.