Quote a Solana transaction fee before requesting a signature
A wallet displaying a transfer preview needs a fee for the exact message the user will sign. The RPC accepts the serialized message before signatures are attached.
Serialize the proposed message
Finish the account list and instructions, including the compute-budget settings. Insert a recent blockhash, serialize the legacy or v0 message, encode the bytes as base64 and substitute them below. The signature count prefix and signature array from a wire transaction are outside the message.
{
"jsonrpc": "2.0",
"id": 1,
"method": "getFeeForMessage",
"params": [
"BASE64_MESSAGE",
{
"commitment": "confirmed"
}
]
}
Display the quote and detect stale previews
For an ordinary SOL transfer of 1,000,000 lamports, a sample fee of 5,000 gives a payer debit of 1,005,000 if that payer is also the sender. Extra instructions that move funds or create accounts change the expected debit. Keep the fee as its own field.
A null value leaves the quote unresolved. Obtain a fresh blockhash and rebuild the candidate message before querying again. If a user changes the priority price, requote the changed message before signing.