该交易通过JSON-RPC被推送到以太坊API节点.节点将交易广播到 P2P网络.矿工从内存池.创建一个新块.矿工将新创建的块广播回对等网络.您的以太坊节点将拾取新的区块.Web3.js后端应用程序从以太坊节点中轮询或订阅与智能合约相关的事件.触发了后端事件web3.js处理程序状态更改在新块中.请注意,在较小的区块链重组.无论是重组还是重组,事件处理程序都会为每个竞争块再次触发(两次,三次等).小型区块链重组可能在一小时内发生多次.当前状态是概率性的,因此您始终需要等待几步才能确定.对于区块链中其他参与者的事件和交易,您只需订阅事件并在矿工将新区块到达您的节点时对其进行处理.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 transacrionlisten to eventsmy questions are:What is the component sending the transaction? Is it the backend component or the geth node?Then suppose that another smart contract in the network emits an event that I want to capture. What is the component that captures the event? Is it the backend component or the geth node? 解决方案 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. 这篇关于发送交易和接收事件在以太坊区块链的后端如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-16 12:15