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 Signing Process
Section titled “The Signing Process”The API returns a base64-encoded wire transaction. This is the serialized transaction format that Solana uses. To sign it:
- Decode from base64 to get the transaction bytes
- Sign the transaction with your keypair
- Re-encode back to base64 wire format
Your private key stays on your machine during this entire process.
Code Examples
Section titled “Code Examples”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 → Transactionconst unsignedTx = getTransactionDecoder().decode( Buffer.from('BASE_64_ENCODED_UNSIGNED_TRANSACTION', 'base64'),);
// 3) Signconst signedTx = await signTransaction([signer], unsignedTx as any);
// 4) Serialize Transaction → base64 wireconst signedTxBase64Wire = getBase64EncodedWireTransaction(signedTx);console.log(signedTxBase64Wire);import base64import base58from solders.keypair import Keypairfrom solders.transaction import VersionedTransaction
# 1) Create signer (base58-encoded 64-byte secret key)SECRET_KEY_BASE58 = "SECRET_KEY_BASE58"signer = Keypair.from_bytes(base58.b58decode(SECRET_KEY_BASE58))
# 2) Deserialize base64 wire → VersionedTransactionunsigned_bytes = base64.b64decode("BASE_64_ENCODED_UNSIGNED_TRANSACTION")unsigned_tx = VersionedTransaction.from_bytes(unsigned_bytes)
# 3) Sign (rebuild the tx with the same message + new signature)signed_tx = VersionedTransaction(unsigned_tx.message, [signer])
# 4) Serialize VersionedTransaction → base64 wireSIGNED_TX_BASE64_WIRE = base64.b64encode(bytes(signed_tx)).decode("utf-8")print(SIGNED_TX_BASE64_WIRE)- Sign fast:
expiresAtis 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.