Wallet API
Broadcast transaction

Broadcast transaction#

To broadcast a transaction to the blockchain, the server calls the POST /api/v5/waas/wallet/pre-transaction/send-transaction endpoint. This ensures the user's transaction is recorded on the blockchain.

// Define your parameters
const postSendTransactionBody = {
    signedTx: "0xf8aa6a84ee6b280083012e389455d398326f99059ff775485246999027b319795580b844a9059cbb000000000000000000000000e0f7a45f1aa6cfff6fbbb1049f7a8c9248312c2e00000000000000000000000000000000000000000000000000000002540be4008193a0dfecbffac07db267e7438fe94f48c0d30bb17c3d86774bd445a9d70d06a974e9a0363c583a80dfc099d3a4186ce943d4bb38420dd52e23d26d30a73bfa8e291ed9",
    chainId: "1",
    accountId:"13886e05-1265-4b79-8ac3-b7ab46211001",
    fromAddr: "0x238193be9e80e68eace3588b45d8cf4a7eae0fa3",
    toAddr: "0xe0f7a45f1aa6cfff6fbbb1049f7a8c9248312c2e",
    txHash: "0x585efb06371c2827a8da7b3dc2f0d3daf4f61cd14959c928bc698c43822881c3",
    txAmount: "10000000000",
    serviceCharge: "4128241194000",
    tokenAddress: "0x55d398326f99059ff775485246999027b3197955",
    txType: "transfer",
    extJson: {
        gasPrice: "196582914",
        gasLimit: "21000",
        nonce: "578"
    }
   };

// Define the helper function
const sendTransactionData = async () => {
    const apiRequestUrl = getRequestUrl(
      apiBaseUrl,
      'api/v5/waas/wallet/pre-transaction/send-transaction'
    );
    return fetch(apiRequestUrl, {
      method: 'post',
      headers: headersParams,
      body: JSON.stringify(postSendTransactionBody),
    })
      .then((res) => res.json())
      .then((res) => {
        return res;
      });
  };

const { data: sendTransactionData } = await sendTransactionData();

Upon successfully sending the transaction, you will receive the following response:

{
        "code": 0,
        "msg": "success",
        "data": [{
                "orderId": "469356614923743232"
        }]
}