I am working on an ethereum project but I have some doubts. I have a backend that connects to the blockchain via web3.js. To connect to the blockchain I use a geth node. I understand that the sequence is this:
send transacrion listen to events my questions are:
An Ethereum transaction refers to an action initiated by an externally-owned account, in other words an account managed by a human, not a contract. For example, if Bob sends Alice 1 ETH, Bob's account must be debited and Alice's must be credited. This state-changing action takes place within a transaction.
Ganache is a personal blockchain for rapid Ethereum and Corda distributed application development. You can use Ganache across the entire development cycle; enabling you to develop, deploy, and test your dApps in a safe and deterministic environment. Ganache comes in two flavors: a UI and CLI.
Events. Smart contracts have the ability to "emit" events during execution. Events are also known as "logs" in Ethereum. The output of the events are stored in transaction receipts under a logs section.
A very good question, sir.
Usually, in setups like this backend signs the transaction with its wallet key. The backend has a hot wallet with ETH balance to be able to create and broadcast transactions.
The transaction is pushed to Ethereum API node over JSON-RPC. The node broadcasters the transaction to P2P network. A miner picks up the transaction from the mempool. A new block is created. The miner broadcasts the newly crated block back to the peer-to-peer network. Your Ethereum node picks up the new block. Web3.js backend application polls or subscribes events related to the smart contracts from your Ethereum node. Backend event web3.js handlers are fired for the state changes in the new block.
Note that the blocks can be also rolled back in the case of a minor blockchain reorganisation. In the case or reorganisation, the event handlers fire again (twice, thrice, etc.) for each competing block. Minor blockchain reorganisation may occur many times in an hour. The current state is probabilistic, so you always need to wait for a few blocks to be sure.
For events and transactions by other actors in the blockchain, you just subscribe to the events and process them as new blocks arrive from miners to your node.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With