How to check transaction finality in Moonbeam network

The finality of transactions on the chain means that a transaction on the chain is almost certain, which also means that the transaction cannot be changed or reversed. Moonbeam is committed to being compatible with Ethereum Web3 API and EVM, but developers still need to understand the difference between Moonbem and Ethereum in determinism. At Moonbeam, we provide finality using a hybrid consensus protocol based on Nominated Proof-of-Stake (NPoS).

Probabilistic certainty represents the probability that a block (and all its transactions) will not be reverted, and this probability increases with the number of confirmed blocks . Therefore, the more confirmed blocks, the higher the probability that the transaction cannot be recovered, the safer the transaction, and the lower the possibility of the transaction being tampered with and reorganized. As suggested in Vitalik's blog on determinism: "You can wait for 13 confirmations to give the attacker a 1 in 1 million chance of success."

We will use technical language to elaborate on how Moonbeam achieves total certainty and how to query transaction certainty.

Moonbeam is deterministic, transactions are usually finalized within 1 to 2 blocks after the block containing the transaction in the Polkadot relay chain . To check the certainty of a specific transaction, Moonbeam provides two custom JSON RPC endpoints that allow you to check whether a specified block or transaction has been finalized, and the operation will return a yes/no response based on the certainty status.

In more detail, you can use the "moon_isBlockFinalized" function to confirm whether the block has been finalized by providing the block hash. Similarly, you can also use "moon_isTxFinalized" to confirm whether the transaction has been finalized by providing the transaction hash. The result will look like the image below:

While you're at it, don't forget to double-check the parameters you enter. When you are checking the finality of a specific block, you need to provide the hash of the block instead of the block number. In the meantime, make sure that the RPC URLs you use are relevant to the network you wish to query.

In addition to using functions to query block/transaction certainty via JSON RPC, Moonscan, the Moonbeam network block explorer , provides an easier query channel, which shows the certainty status of blocks and transactions. Unconfirmed blocks/transactions will be displayed in the form of an hourglass, while confirmed blocks/transactions will be represented by a green ✅. An example is shown in the figure below:

If you want to learn about how Moonbeam custom JSON RPC endpoints check transaction certainty and related content, you can direct to this page of the official Moonbeam documentation website .

Guess you like

Origin blog.csdn.net/Moonbuilder/article/details/131841695