Once a transaction is committed to the blockchain is there a way to let an entity outside the blockchain (i.e. An entity that is not a node in the blockchain) know that a particular transaction has been committed?
2 Answers
Yes this is possible.
The smart contract needs to emit events which are written to logs. Your entities outside the blockchain can read these logs from the blockchain nodes.
-
Thank you for your reply. I was wondering could a blockchain node read a value stored in a variable in the smart contract through some EVM memory read program and send it to someone outside. I believe a smart contract is stored in the storage trie of each blockchain node and if so can't something like this happen?– DeepalCommented Jan 23, 2020 at 14:09
event
definitions and emit
steps are the go-to contract design step to be courtious to external clients using event listeners. Similar to subscribing to a feed and they can listen to specific contracts and topics, apply filters and so on.
An entity that is not a node
This is sort of a challenge. If they don't have their own then they will rely on something that does to inform them. Somebody (reliable) has to be listening to Ethereum.
You can set up your own caching server to catch interesting events and pass them on, or rely on a third-party API to do it. Something like: https://blog.infura.io/faster-logs-and-events-e43e2fa13773/
Hope it helps.
-
Thank you for your reply. I was wondering could a blockchain node read a value stored in a variable in the smart contract through some EVM memory read program and send it to someone outside. I believe a smart contract is stored in the storage trie of each blockchain node and if so can't something like this happen?– DeepalCommented Jan 23, 2020 at 14:10
-
Sure. The convenient way is the contract presents an inspector function that fetches it politely. Any node has a copy of the chain, and the data is in slots with computable keys in a 2^256 slot namespace. Nothing can be protected from a determined viewer and nothing can stop that viewer from presenting an API or sending a message. Commented Jan 23, 2020 at 21:34
-
Just so we're clear, that's what a node is, so not quite in line with "An entity that is not a node." Ethereum is a protocol spec and it's indifferent to what you use to listen for blocks, validate them, process the transactions and know the state. With those bases covered you can surface any value in the state. Certainly, the easiest way to accomplish that is to run one of the existing node implementations. Commented Jan 23, 2020 at 21:36