Skip to main content

Transaction Receipt

Transaction receipt is the data structure that contains information about the transaction execution result.

Transaction Receipt

The receipt can be obtained through the RPC method cfx_getTransactionReceipt. This method takes the transaction hash as a parameter and returns null if the transaction has not been executed, or a Receipt object after execution is completed.

Receipt Fields

The Receipt contains the following types of information:

  • Basic transaction information: transactionHash, from, to
  • On-chain transaction information: blockHash, epochNumber, index
  • Transaction execution result: outcomeStatus (0 for success, 1 for failure)
  • Gas & storage fee information: gasUsed, gasFee, storageCollateralized, gasCoveredBySponsor, storageCoveredBySponsor, storageReleased
  • Deployed contract address: contractCreated (if it is a contract deployment transaction)
  • Contract execution logs: logs
  • Execution error information: txExecErrorMsg (if the transaction execution fails)

For detailed information about each field, you can refer to the API documentation for cfx_getTransactionReceipt.

logs

The logs field in the Receipt is an array containing all the logs generated during the transaction execution process. When interacting with a contract, the contract can produce logs or events using emit statements. After the transaction is executed, these logs are recorded in the transaction receipt. In Solidity, Events are designed to log information about the execution of contract methods, providing detailed information about contract execution through events.

You can retrieve logs using the cfx_getLogs method and decode the log data using the abi.decode method. Conflux SDKs also provide methods to help decoding the logs, for example, javascript and python.

Execution Failure

Execution failures can be due to errors that occurred during the contract execution process or errors returned when estimating gas cost through the estimate interface. To find the specific reason for the transaction failure, check the txExecErrorMsg under the receipt:

  1. VmError(OutOfGas): The transaction specified gas is used out during transactioin execution.
  2. VmError(ExceedStorageLimit): The transaction specified storageLimit(upper-limit storage can be used) is not enough.
  3. NotEnoughCash: Insufficient user balance to cover transaction cost.
  4. Vm reverted, Reason provided by the contract: xxxx: The contract execution failed with details provided.
  5. VmError(BadInstruction xxxx): Contract deployment failed.
  6. Vm reverted, xxxx: The contract execution failed with no details provided.

Solution: Depending on the specific error message, you may need to increase gas, increase storageLimit, ensure sufficient balance, or debug the contract code to identify and fix the issues causing the failure.

Remember that when handling transaction errors, it's essential to identify the root cause of the error and apply the appropriate solution. In most cases, modifying transaction parameters, waiting for node synchronization, or debugging the contract code can help resolve the issues.

FAQs

What is a transaction receipt, and what information does it contain?

A receipt is the receipt information of a transaction. Through a receipt, you can know some results of the transaction execution, such as whether the transaction is successful, whether a contract is created, gas fee usage, eventLog generated by a transaction execution, etc.

Why can't I retrieve the receipt for a transaction?

The receipt information for a transaction can only be obtained after the transaction has been successfully executed. If the transaction has not been completed, the receipt will be null.

Can the receipt information for a transaction change?

The receipt information may change immediately after a transaction is executed and included in a block. However, once the transaction is finalized, the receipt information will not change.

How do I know that a transaction has been successfully executed?

Check the status field of the transaction or the outcomeStatus field of the receipt to determine whether the transaction is successful, 0 means success and 1 means failure.

Why would a transaction execution fail?

Execution Failure.

How to know whether a transaction is safe and confirmed?

If the epochNumber of the epoch that the transaction belongs to is less than the currently confirmed epochNumber, it is considered safe. You can also get the confirmationRisk of the block that the transaction belongs to through the cfx_getConfirmationRiskByHash RPC. If the obtained value is less than 1e-8, it is considered safe.

How does the status of the transaction change?

After the transaction is submitted through RPC, it will go through several states: Waiting for packaging -> packaging -> execution -> confirmation.

Why does a transaction keep on waiting to be packaged?

If a transaction has not been packaged for a long time, it’s likely that either the nonce is set incorrectly or the balance is not sufficient.