发送交易和接收事件如何在以太坊区块链的后端工作
How sending transactions and receiving events work in backends in Ethereum blockchain
我正在做一个以太坊项目,但我有一些疑问。我有一个通过 web3.js 连接到区块链的后端。为了连接到区块链,我使用了一个 geth 节点。
我知道顺序是这样的:
发送交易
听事件
我的问题是:
- 发送交易的组件是什么?是后端组件还是geth节点?
- 然后假设网络中的另一个智能合约发出了一个我想要捕获的事件。捕获事件的组件是什么?是后端组件还是geth节点?
问得好,先生。
通常,在这样的后端设置中 signs the transaction with its wallet key. The backend has a hot wallet 具有 ETH 余额,以便能够创建和广播交易。
交易被推送到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新区块的状态变化。
请注意,在未成年人 blockchain reorganisation 的情况下,块也可以回滚。在案例或重组中,事件处理程序为每个竞争块再次触发(两次、三次等)。小型区块链重组可能在一个小时内发生多次。当前状态是概率性的,所以你总是需要等待几个区块才能确定。
对于区块链中其他参与者的事件和交易,您只需订阅事件并在新区块从矿工到达您的节点时处理它们。
我正在做一个以太坊项目,但我有一些疑问。我有一个通过 web3.js 连接到区块链的后端。为了连接到区块链,我使用了一个 geth 节点。 我知道顺序是这样的:
发送交易
- 发送交易的组件是什么?是后端组件还是geth节点?
- 然后假设网络中的另一个智能合约发出了一个我想要捕获的事件。捕获事件的组件是什么?是后端组件还是geth节点?
问得好,先生。
通常,在这样的后端设置中 signs the transaction with its wallet key. The backend has a hot wallet 具有 ETH 余额,以便能够创建和广播交易。
交易被推送到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新区块的状态变化。
请注意,在未成年人 blockchain reorganisation 的情况下,块也可以回滚。在案例或重组中,事件处理程序为每个竞争块再次触发(两次、三次等)。小型区块链重组可能在一个小时内发生多次。当前状态是概率性的,所以你总是需要等待几个区块才能确定。
对于区块链中其他参与者的事件和交易,您只需订阅事件并在新区块从矿工到达您的节点时处理它们。