Skip to main content

Sending a Manually Built Transaction

Once you have constructed and signed your transaction manually, the next step is broadcasting it to the network. This guide explains how to send the transactions created during the manual transaction-building process.

DEPRECATED

Manually sending transactions can be error-prone due to gas miscalculations or incorrect UTXO usage. Prefer using the Simulation Method, which automates gas estimation and UTXO management, ensuring reliability and efficiency.


Sending Raw Transactions

To send manually built transactions, use the sendRawTransaction method from the JSONRpcProvider. Each signed transaction from the TransactionFactory output must be sent sequentially.


Example: Sending Manually Built Transactions

const firstTx = await provider.sendRawTransaction(signedTransaction[0], false);

if (!firstTx || !firstTx.success) {
throw new Error("First transaction failed");
}

const secondTx = await provider.sendRawTransaction(signedTransaction[1], false);

if (!secondTx || !secondTx.success) {
throw new Error("Second transaction failed");
}

console.log("Transaction hash:", secondTx.result);
Explanation
  1. First Transaction:
    The first signed transaction is sent to the network. It must succeed before proceeding to the second transaction.

  2. Second Transaction:
    The second signed transaction depends on the success of the first. Broadcast it only if the first transaction is successful.

  3. Result:
    The final transaction hash (secondTx.result) confirms the successful completion of the process.

Note

Ensure you send transactions in the correct order, as subsequent transactions may depend on earlier ones.


Best Practices

  • Ensure your transaction includes adequate gas to avoid failures.
  • Double-check that the selected UTXOs are valid and sufficient for the transaction.
  • Always send transactions in the correct order, as subsequent transactions may depend on earlier ones.
  • Record transaction hashes for auditing and debugging purposes.