Skip to main content

Transaction FAQs

How to send a transaction?#

The easiest way to send a transaction is to use a wallet such as Conflux Portal, and click “send” to directly set the amount. If you are a developer, you can use the Conflux SDK (JS, Java, Go) to construct the transaction yourself, and then send it to the chain via the node RPC.

What are the gas and storage fees when sending a transaction?#

The gas fee is a fee required for transaction execution. Miners need to charge a certain amount of fee for packaging and executing the transaction. The way to calculate the gas fee is gasFee = gasPrice * gasUsed. Additionally, the execution of the transaction may occupy new storage space. Even though you don't need to pay for the occupation of this space, a certain amount of CFX needs to be staked for the use of this storage. As the storage is released, the staked CFX will be returned. The storage fee refers to the amount of staked CFX for the storage used, and 1 CFX is required per 1024 bytes used.

What information (parameters) need to be specified when using the SDK to send transactions?#

If you make simple CFX transfers using JS-SDK, you only need to specify from (transfer from which account), to (send to which account), value (quantity to send, unit: Drip).

In addition to from, to, value, what information does a TX contain?#

  • from: the address of the transaction sender. It cannot be empty, and can only be an externally owned account, not a smart contract’s address.
  • to: the recipient of the transaction, which can be empty. If it is empty, the information in data will be used to create a smart contract. The address of the newly created contract can be found in the transaction receipt.
  • value: transaction amount (unit: Drip).
  • nonce: the serial number of the transaction execution. Usually, the counting of the number starts from 0 and increases by 1 when every transaction is sent. The execution of the transaction will also be processed in an increasing order without skipping. You can get the next nonce of an address using cfx_getNextNonce.
  • gas: the upper limit of the amount of gas fee that can be consumed for transaction execution.
  • gasPrice: the price of the transaction gas (unit: Drip).
  • storageLimit: the maximum storage limit that can be paid for transaction execution.
  • chainId: the ID of the chain. It’s used to distinguish transactions between different chains. Mainnet’s is 1029, and testnet’s is 1.
  • epochHeight: it’s used to specify the epoch range to execute the transaction (epochHeight, epochHeight + 10000). Transactions beyond this range will not be packaged.
  • data: transaction data, which can be remarks, creation ByteCode of a contract, or interaction data of a contract.

How to get the correct nonce?#

\ Through the cfx_getNextNonce RPC, the next available nonce of an account can be obtained. The used nonce cannot be used again. The transaction will not be packaged if using a nonce with a value greater than the current nonce.

When will the nonce increase by 1? Will the nonce increase by 1 if the transaction fails? Why has the nonce not changed when the transaction has been sent?#

The nonce increases once the transaction is executed, whether it succeeds or fails. After the transaction is sent, the nonce queried through cfx_getNextNonce stays unchanged because the transaction has not been executed. At this time, the transaction may be in the transaction pool and has not been packed, or it may have just been packed and be in the defer state, waiting to be executed.

How to calculate the gas fee actually used in the transaction?#

On ConfluxScan, users can view gas usage, gas price, gas fee, and other relevant information of a transaction, which is obtained through cfx_getTransactionReceipt: gasFee = gasCharged * gasPrice, but the gasCharged is not necessarily equal to gasUsed. There is a rule in Conflux: gas is used to set the upper limit of gas that can be used in a transaction. It must be greater than the actual gas used value (gasUsed). For the excessive part, at most, only 1/4 will be refunded: if the excessive part is less than 1/4 of the gasLimit, all will be refunded, but if it is greater than 1/4, only 1/4 will be returned. Hence, try to give an accurate gas value when sending a transaction.

How to release the storage deposit?#

When the storage is released, the deposit is automatically refunded. For example, if the balance of the ERC20 token changes from non-zero to 0, the deposit will be refunded. If a contract is destroyed, the deposit generated by the interaction between all addresses and the contract will be refunded as well.

Why has the balance not changed after interacting with a contract and the gas fee is paid for this transaction?#

The Conflux network has a sponsor mechanism. If a contract has a sponsor, the gas and storage fees for this contract’s interactions will be paid by the sponsor.

If you want to send transactions in batches, how to manage nonce?#

When sending transactions in batches, you need to manually manage the nonce. Every time you send a transaction, the nonce is manually incremented by one. In this case, for a failed transaction of which nonce is not used, you need to manually adjust the transaction parameters to resend it. Therefore, you need to keep all transaction hashes and monitor the status of the transactions when sending in batches.

How to know the amount of gas and storage used by a transaction?#

The cfx_estimateGasAndCollateral RPC can be used to estimate the amount of gas and storage that a transaction needs to use, but the estimation is not 100% accurate. Hence, the returned gas can be adjusted manually, such as multiplying by 1.3.

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.

How to determine 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.

What is a 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. Reference

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. Reference:

Why does a transaction fail?#

There are several reasons for a failure of a transaction:

  1. Reuse an old nonce.
  2. Used a new nonce, but there is a transaction with the same nonce in the transaction pool.

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.

Why would a transaction execution fail?#

Transaction execution failures are roughly divided into the following situations:

  • Vm reverted, Reason provided by the contract: ’xxxxx’: the contract execution failed, and the contract returned detailed information
  • VmError(ExceedStorageLimit): the specified storage limit is not enough
  • NotEnoughCash {required: 22625000000010862646, got: 22062499999972687418, actual_gas_cost: 10862646, max_storage_limit_cost: 22625000000000000000}: insufficient balance
  • VmError(OutOfGas): the specified gas fee is not enough
  • VmError(BadInstruction {instruction: 238 }): contract deployment failed
  • Vm reverted: the contract execution failed, but the contract did not return detailed information