Partial signing lets multiple parties sign the same transaction at different
times or on different devices. A coordinator builds the message, each required
signer signs the exact serialized message bytes, and the coordinator verifies
and merges the signatures before submission.
Signatures authorize bytes, not intentChanging the fee payer, blockhash, instruction order, account list, or any
instruction data produces a different message and invalidates every signature
already collected.
Partial signing flow
- Agree on the transaction instructions and who will pay the fee.
- Set the transaction lifetime and fee payer.
- Serialize the message once. Treat those bytes as immutable.
- Distribute the message bytes and a human-readable summary to each signer.
- Collect and verify each Ed25519 signature against the same message bytes.
- Attach signatures to their required signer addresses.
- Confirm that every required signature is present and valid, then submit.
Complete example
The fee payer and SOL sender below sign independently. The coordinator verifies
both signatures, merges them, and submits the completed transaction.
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide to keep the class-based API.To run this code, install 1.x with npm install @solana/web3.js@1. A plain npm install @solana/web3.js installs v3, which this code doesn’t run on.
import {
Connection,
Keypair,
LAMPORTS_PER_SOL,
SystemProgram,
Transaction,
} from "@solana/web3.js";
import nacl from "tweetnacl";
const connection = new Connection("http://localhost:8899", "confirmed");
const feePayer = Keypair.generate();
const sender = Keypair.generate();
const recipient = Keypair.generate();
const feePayerAirdrop = await connection.requestAirdrop(
feePayer.publicKey,
LAMPORTS_PER_SOL,
);
const feePayerAirdropLifetime = await connection.getLatestBlockhash();
await connection.confirmTransaction({
...feePayerAirdropLifetime,
signature: feePayerAirdrop,
});
const senderAirdrop = await connection.requestAirdrop(
sender.publicKey,
LAMPORTS_PER_SOL,
);
const senderAirdropLifetime = await connection.getLatestBlockhash();
await connection.confirmTransaction({
...senderAirdropLifetime,
signature: senderAirdrop,
});
// Agree on every message field before asking anyone to sign.
const lifetime = await connection.getLatestBlockhash();
const transaction = new Transaction({
feePayer: feePayer.publicKey,
blockhash: lifetime.blockhash,
lastValidBlockHeight: lifetime.lastValidBlockHeight,
}).add(
SystemProgram.transfer({
fromPubkey: sender.publicKey,
toPubkey: recipient.publicKey,
lamports: 100_000_000,
}),
);
// These exact bytes are the frozen message distributed to every signer.
const messageBytes = transaction.serializeMessage();
// Each party can sign the same bytes independently, including offline.
const feePayerSignature = nacl.sign.detached(messageBytes, feePayer.secretKey);
const senderSignature = nacl.sign.detached(messageBytes, sender.secretKey);
// Verify each signature before attaching it to the transaction.
if (
!nacl.sign.detached.verify(
messageBytes,
feePayerSignature,
feePayer.publicKey.toBytes(),
)
) {
throw new Error("Invalid fee payer signature");
}
if (
!nacl.sign.detached.verify(
messageBytes,
senderSignature,
sender.publicKey.toBytes(),
)
) {
throw new Error("Invalid sender signature");
}
// The coordinator merges signatures by their required signer address.
transaction.addSignature(feePayer.publicKey, Buffer.from(feePayerSignature));
transaction.addSignature(sender.publicKey, Buffer.from(senderSignature));
if (!transaction.verifySignatures()) {
throw new Error("The transaction does not have valid required signatures");
}
const signature = await connection.sendRawTransaction(transaction.serialize());
await connection.confirmTransaction({ ...lifetime, signature });
console.log("Transaction signature:", signature);
// Any message mutation invalidates every signature already collected.
const mutatedTransaction = Transaction.from(transaction.serialize());
mutatedTransaction.add(
SystemProgram.transfer({
fromPubkey: sender.publicKey,
toPubkey: recipient.publicKey,
lamports: 1,
}),
);
console.log("Signatures still valid:", mutatedTransaction.verifySignatures());
The example uses raw Ed25519 signing to make the boundary between the
coordinator and each signer explicit. A wallet, hardware device, custody
service, or offline signer can replace either local keypair as long as it signs
the exact same message bytes.
Freeze the message before signing
Every signature covers the serialized transaction message. The message includes
all of the following:
- the fee payer
- the recent blockhash or durable nonce
- every program and account address
- account signer and writable permissions
- instruction order and instruction data
Build these fields first, serialize the message once, and distribute that byte
array to every signer. It is useful to store a digest of the message alongside
each signing request so the coordinator can reject a signature returned for a
different message.
Do not deserialize a message, change it, and expect previously collected
signatures to remain valid. Even a change that appears operational, such as
replacing an expired blockhash or changing the fee payer, requires every signer
to sign again.
Coordinate the fee payer
The fee payer is always a required signer and must be chosen before the message
is frozen. Confirm that the account has enough SOL for the base fee and any
priority fee. If a sponsor or backend will pay the fee, put that address in the
message before collecting the user’s signature; adding the sponsor later changes
the signed bytes.
The coordinator should verify that an incoming signature belongs to an address
listed as a required signer. Never accept an arbitrary public key and append it
to the transaction.
Manage transaction lifetime
A recent blockhash transaction is only valid while its blockhash remains in the
validator’s recent blockhash queue. Before starting a multi-party signing flow,
estimate whether all signers can respond before lastValidBlockHeight.
If the blockhash expires, build a new message with a fresh blockhash and collect
all signatures again. For workflows that may take longer or include offline
signers, use a durable nonce. A
durable nonce avoids the recent blockhash window, but advancing or otherwise
consuming that nonce still invalidates the pending transaction.
Verify before submission
For every returned signature:
- Verify the signature against the frozen message bytes and the expected
signer’s public key.
- Attach it to that signer’s slot in the transaction signature array.
- Verify the assembled transaction has valid signatures for every required
signer.
- Submit the serialized transaction without rebuilding its message.
After submission, confirm using the same lifetime information that was included
in the signed message. If confirmation reports an expired blockhash or consumed
nonce, do not retry with a modified transaction; restart the signing flow.