Important: Ensuring Transaction Finality​

If you intend to add "deposit" and "withdrawal" functionalities to your implementation, it is important that you ensure that transactions are final before the backend system credits or deducts funds from a user account.

In brief, transactions pass through several phases before they are finalised and included in a block.

The status "code" recorded for each of these phases can differ, so be sure to check that it is 0 (meaning success) for each of them. A non-zero "code" indicates that there was a problem with the transaction during processing.

For example, this transaction was invalid because the order was already canceled. You can query that the code for this transaction is 405.

{

code: 393621,

hash: "F296E84917A92FC4876AFE77DE662CC9417F9D6F2EB8ED1AD723A5433EBB8362",

height: "30771453",

log: "{"codespace":6,"code":405,"abci_code":393621,"message":"Failed to find order [E0B781A5DA419E0E596D13FE8A06BF5F9CE9C37D-19450]"}",

ok: false,

tx: {

type: "auth/StdTx",

value: {

data: null,

memo: "",

msg: [

{

type: "dex/CancelOrder",

value: {

refid: "E0B781A5DA419E0E596D13FE8A06BF5F9CE9C37D-19450",

sender: "bnb1uzmcrfw6gx0quktdz0lg5p4lt7wwnsmat6ksd6",

symbol: "BNB_TUSDB-888"

}

}

],

signatures: [

{

account_number: "153135",

pub_key: {

type: "tendermint/PubKeySecp256k1",

value: "AzWMnQAwvCP9mbpNyaGuOtNVum1ktvlBb+XFy8D50xmh"

},

sequence: "19452",

signature: "y2FTS4rAqWvDmNWLxsOg+8vrz9XZ4gDXs/tGh/psnQwRMQBtw1x1a2TSCgc0G4qbvh0YICe5ZvJFRNvg/zGG7w=="

}

],

source: "889"

}

}

}

The two phases we should be concerned about are CheckTx and DeliverTx.

We recommend that you broadcast your transactions via REST API or, if you wish to run a Full Node, Node RPC via the BroadcastTxSync command.

While there is an RPC command called BroadcastTxCommit which will wait for both CheckTx and DeliverTx and return with codes for both and a block height, it is unfortunately not recommended for use in production.

Instead, there are two ways that you can go about checking the status of your transaction after you have broadcasted it.

If you haven't received anything after a couple of blocks, resend the transaction. If the same happens again, send it to some other node. This is safe to do so long as you are broadcasting the same transaction. Transactions are unique in the blockchain and you cannot spend the coins twice by retrying the send of the same data.

Last updated