Why is the deal never packaged?

Due to the low throughput rate and high usage threshold of the current blockchain, it is inevitable to encounter the problem of delayed transaction packaging when sending transactions through the blockchain. Take Conflux as an example. Normally, two blocks are generated in a second in the Conflux network. Once a transaction is successfully sent, it will be packaged and executed within a few to ten seconds. If the transaction is not packaged, there is a high probability that something is wrong and requires manual intervention from the sender.

How to determine the cause of pending transactions

If a Pending transaction is successfully propagated to the transaction pool of the node used in Scan, the transaction can be searched by hash in Scan. The status of the transaction can be seen as Pending in the transaction details page

At this time, we can enter the account details page of the transaction sender and check the Pending transactions of the user by clicking the Pending transaction list Tab of the account

In this TAB you can see the total number of pending transactions for the current user, as well as the earliest pending transactions (up to 10). The pending cause of the first pending transaction can also be seen. There are three possible causes:

  • Wrong nonce
  • Insufficient balance
  • Ready to pack

This page is actually cfx_getAccountPendingTransactions through RPC methods to obtain some account of the current pending transactions

Wrong nonce

This error indicates that the sent transaction uses the wrong Nonce. Normally, the transaction needs to be executed in the Nonce order one by one. If the nONCE of a transaction is preceded by one or more unexecuted transactions, the transaction waits until all previous transactions are successfully executed.

In this case we need to resend the transaction using the correct Nonce. Note that pending transactions are executed automatically when all preceding transactions are executed (and the balance is sufficient).

Insufficient balance

In Conflux network, if the sender balance of a transaction is not enough to pay the amount + handling fee of a transaction, the transaction can also be successfully sent to the transaction pool, but it will be in the pending state and will not be packaged for execution. In this case, it is only necessary to transfer enough CFX to the account.

Ready to pack

In this case, the transaction itself has reached the conditions to be packaged, but is not packaged because of network congestion or other reasons.

If the transaction stays in this state for a long time, the gasPrice of the transaction can be appropriately increased to resend the transaction, which can improve the packaging execution speed of the transaction.

How to set gasPrice correctly

The speed of packaging execution of a transaction is mainly affected by the gasPrice of the transaction. The higher the gasPrice is, the faster the chain is, so it is very important to set the gasPrice correctly.

You can use fullNode’s cfx_gasPrice RPC method to get a recommended gasPrice value. This method gives a recommended value based on the gas usage of a certain number of recent blocks and the gasPrice of the transactions in them.

The most ideal way is to calculate an appropriate gasPrice according to the gasPrice Settings of transactions in the network node transaction pool, but currently there is a lack of relevant RPC method support.