Sign and Broadcast Transaction

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

1. Prepare unsigned transactions in Base64 encrypted format.

2. Sign the transaction using the following code:

import { Ed25519Keypair, RawSigner } from '@mysten/sui.js';

const keypair = Ed25519Keypair.fromSecretKey(
  Uint8Array.from(Buffer.from(process.env.PRIVATE_KEY!, 'hex'))
);
const signer = new RawSigner(keypair, provider);

// Convert unsigned hex string to bytes
const txBytes = Uint8Array.from(Buffer.from(process.env.UNSIGNED_TX!, 'hex'));

const { signature } = await signer.signTransactionBlock(txBytes);

console.log('Signed TX:', signature);

3. Broadcast via API

Example request:

curl --location 'https://api-test.p2p.org/api/v1/sui/testnet/transaction/send' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
  "signedTransaction": "<your_signed_transaction_hex>",
  "sender": "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3"
}'
  • signedTransaction — your locally signed transaction, hex-encoded.
  • sender — wallet address used for the original unsigned transaction.

Example response:

{
    "error": null,
    "result": {
        "transactionDigest": "DiXajfAeTLVhiQZuW8aH2UD1XsCEoZVH4twRC5PjeK5"
    }
}
  • txHash — hash of the submitted transaction.
  • status — expected to be "Success" on successful submission.
    May also return "Pending" or an error depending on network state.

Use the txHash to track the transaction status in explorers like SuiScan.

What's Next?