Sign and Broadcast Transaction

To sign and broadcast a transaction to the SUI network, follow these steps:

1. Prepare the Unsigned Transaction

Obtain the unsignedTransaction object by following the staking, vote, or undelegate flow via the Staking API.
The object will have the format returned in previous API responses.

2. Sign the Transaction:

Use the tronweb library to sign the transaction with your private key.

// sign-tron-tx.mjs
import { TronWeb } from 'tronweb';
import dotenv from 'dotenv';

dotenv.config();

const tronFullHostUrl = 'https://nile.trongrid.io';
const tronPrivateKey = process.env.TRON_PRIVATE_KEY;

const unsignedTx = {
    "visible": false,
    "txID": "c07e64f57ebb6ae191404b1c693aa46f80789aceacbfd8cc17a7c85c0c8c5559",
    "raw_data_hex": "0a02ee182208eb04b8cce7cc51534090f5d7edfa325a6a080412660a30747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e566f74655769746e657373436f6e747261637412320a1541da53d324a354aa5924c7117caff3ead97910a5e112190a1541351b95e29c2514b7b8183cbc81a8e08c68e8833b100370b0a0d4edfa32",
    "raw_data": {
        // ... full raw_data from API response ...
    }
};

async function main() {
    if (!tronPrivateKey) throw new Error('TRON_PRIVATE_KEY is not set');

    const tronWeb = new TronWeb({
        fullHost: tronFullHostUrl,
        headers: {
            'TRON-PRO-API-KEY': process.env.TRONGRID_API_KEY,
        },
        privateKey: tronPrivateKey,
    });

    const signedTx = await tronWeb.trx.sign(unsignedTx);

    // Hex-serialize for sending to API (as required)
    const hexSignedTx = Buffer.from(JSON.stringify(signedTx)).toString('hex');
    console.log('✅ Signed transaction hex:', `0x${hexSignedTx}`);
}

main().catch((e) => {
    console.error('Signing failed:', e.message);
    process.exit(1);
});

The output will be a0x-prefixed hex string containing your signed transaction, ready for broadcasting.

3. Broadcast the Signed Transaction

Send a POST request to /api/v1/tron/[network]/transaction/send

Example request:

curl --request POST \
  --url 'https://api-test.p2p.org/api/v1/tron/testnet-nile/transaction/send' \
  --header 'accept: application/json' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "signedTransaction": "0x7b2276697369626c65223a66616c73652c2274784944223a22..."
}'
  • signedTransaction — your locally signed transaction, hex-encoded.

Example response:

{
  "error": null,
  "result": {
    "transactionHash": "c8e47301ca1d4a56120e6f13f0ce5f8a680e2fda221b3d8bc423cc355f924a70",
    "createdAt": "2025-07-04T09:01:10.000Z",
    "network": "testnet-nile",
    "senderAddress": "41da53d324a354aa5924c7117caff3ead97910a5e1",
    "block": null,
    "status": "PENDING",
    "gas": {
      "bandwidthUsed": 0,
      "energyUsed": 0
    }
  }
}
  • transactionHash — hash of the submitted transaction.
  • createdAt — time transaction was broadcast (ISO 8601).
  • network — target TRON network.
  • senderAddress — sender’s address (hex).
  • block — block number if transaction is confirmed, or null if still pending.
  • status — transaction status: PENDING or CONFIRMED.
  • gas
    • bandwidthUsed — bandwidth consumed.
    • energyUsed — energy consumed.

Use the transactionHash to track the transaction status in explorers like Tronscan.

What's Next?