Skip to content

Sign the transaction

After building, the SDK automatically decodes the transaction, signs it locally with your private key and re-encodes it. Your key never leaves your device.

The API returns a base64-encoded wire transaction. This is the serialized transaction format that Solana uses. To sign it:

  1. Decode from base64 to get the transaction bytes
  2. Sign the transaction with your keypair
  3. Re-encode back to base64 wire format

Your private key stays on your machine during this entire process.

The API returns a base64-encoded wire transaction; you decode it, sign it then re-encode it back to base64 wire format.

import bs58 from 'bs58';
import {
getTransactionDecoder,
signTransaction,
getBase64EncodedWireTransaction,
createKeyPairFromBytes,
} from '@solana/kit';
// 1) Create signer (base58-encoded 64-byte secret key)
const SECRET_KEY_BASE58 = 'SECRET_KEY_BASE58';
const signer: CryptoKeyPair = await createKeyPairFromBytes(bs58.decode(SECRET_KEY_BASE58));
// 2) Deserialize base64 → Transaction
const unsignedTx = getTransactionDecoder().decode(
Buffer.from('BASE_64_ENCODED_UNSIGNED_TRANSACTION', 'base64'),
);
// 3) Sign
const signedTx = await signTransaction([signer], unsignedTx as any);
// 4) Serialize Transaction → base64 wire
const signedTxBase64Wire = getBase64EncodedWireTransaction(signedTx);
console.log(signedTxBase64Wire);
  • Sign fast: expiresAt is short (~30s). Build and sign immediately before submitting.
  • Don’t mutate the transaction/message: the submit endpoint validates message bytes against what the server built.