---
id: SI0027
title: "Unsigned transaction handoff"
url: https://carbium.sh/library/si/unsigned-transaction-handoff
collection: AI and blockchain
category: Agent wallets and signing safety
revision: 1
updated: 2026-11-22
author: Carbium
code: MIT (LICENSE in the zip); text: all rights reserved, Carbium Corporation
---

# Unsigned transaction handoff

How an AI agent makes Solana transactions without holding a key: it builds the message unsigned, shows a signer what the bytes do, and hands it over before the blockhash expires. A script builds a SOL transfer and prints the handoff.

## The agent proposes, a signer approves

An agent that makes Solana transactions needs two abilities, and they should live in different processes. One is deciding what to send. The other is holding a key that can send it. A model decides well enough to be useful and badly enough that you want a gate in front of the money. Give it a private key and every injected instruction, odd tool result or misread request can move funds.

The handoff pattern splits the job. The agent builds a transaction message with everything in it except signatures. A separate signer reads the message, signs it and sends it. The signer is a person in a wallet app, or a small service that applies a policy before it signs. The private key never shares a process with the model.

The agent still needs to read the chain to build a good message: a recent blockhash, the fee payer's balance, the fee. A Carbium key is enough for that. Carbium's [swap](https://carbium.sh/docs#swap) method follows the same shape: it builds an unsigned transaction that you sign and send through any RPC. A transfer, a token move or a program call you assemble yourself fits the same pattern.

## What travels in the handoff

| Field | Why the signer needs it |
|---|---|
| Wire transaction in base64 | the bytes to sign, with the signature slots empty |
| Fee payer | the account that pays the fee and must sign |
| Decoded summary | what a person reads, built from the instructions in the message |
| Fee in lamports | the cost before approval |
| Last valid block height | the point after which the transaction can no longer land |
| Payer balance | a warning before an approval that cannot succeed |

The summary has to come from the instructions in the message. If the model writes its own description, an injected instruction can describe a harmless transfer while the bytes carry a different one. Decode the bytes the signer is about to sign and show that, and treat the model's prose as a label at most.

## Build the unsigned message

The script takes a fee payer, a recipient and an amount in lamports, 1,000,000 by default. It builds a System Program transfer by hand: the instruction data is 12 bytes, the instruction index 2 as a little-endian u32 followed by the amount as a little-endian u64. Before any network call it checks the program against an allowlist and the amount against a cap of 5,000,000 lamports, so an agent that proposes more gets refused locally.

`main.ts` (run: `node main.ts <payer> <recipient> [lamports]`)

```ts
// SI0027 · Unsigned transaction handoff
// https://carbium.sh/library/si/unsigned-transaction-handoff
// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.
// SPDX-License-Identifier: MIT

// Build an unsigned SOL transfer for a signer to review. Run: CARBIUM_KEY=... node main.ts <payer> <recipient> [lamports]
import {
  AccountRole, address, appendTransactionMessageInstruction, compileTransaction, createDefaultRpcTransport,
  createSolanaRpcFromTransport, createTransactionMessage, getBase64Decoder, getBase64EncodedWireTransaction, pipe,
  setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, type Instruction,
} from "@solana/kit";

const key = process.env.CARBIUM_KEY;
if (!key) {
  console.error("Set CARBIUM_KEY to your Carbium API key.");
  process.exit(1);
}
const [payerArg, toArg, amountArg = "1000000"] = process.argv.slice(2);
if (!payerArg || !toArg) {
  console.error("Usage: node main.ts <payer> <recipient> [lamports]");
  process.exit(1);
}
const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";
const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));
const SYSTEM = address("11111111111111111111111111111111");
const ALLOWED = new Set<string>([SYSTEM]);
const MAX_LAMPORTS = 5_000_000n;
const payer = address(payerArg);
const to = address(toArg);
const lamports = BigInt(amountArg);
if (lamports <= 0n || lamports > MAX_LAMPORTS) {
  console.error(`Refused: ${lamports} lamports is outside 1..${MAX_LAMPORTS}.`);
  process.exit(1);
}
// System transfer data: instruction index 2 (u32 LE), then the amount (u64 LE).
const data = new Uint8Array(12);
const view = new DataView(data.buffer);
view.setUint32(0, 2, true);
view.setBigUint64(4, lamports, true);
const transfer: Instruction = {
  programAddress: SYSTEM,
  accounts: [
    { address: payer, role: AccountRole.WRITABLE_SIGNER },
    { address: to, role: AccountRole.WRITABLE },
  ],
  data,
};
if (!ALLOWED.has(transfer.programAddress)) throw new Error("Program is not on the allowlist.");
const [latest, payerInfo, height] = await Promise.allSettled([
  rpc.getLatestBlockhash().send(),
  rpc.getAccountInfo(payer, { encoding: "base64" }).send(),
  rpc.getBlockHeight().send(),
]);
if (latest.status !== "fulfilled") throw latest.reason;
const warnings: string[] = [];
if (payerInfo.status !== "fulfilled") warnings.push(`payer read failed: ${payerInfo.reason}`);
if (height.status !== "fulfilled") warnings.push(`height read failed: ${height.reason}`);

const message = pipe(
  createTransactionMessage({ version: 0 }),
  (m) => setTransactionMessageFeePayer(payer, m),
  (m) => setTransactionMessageLifetimeUsingBlockhash(latest.value.value, m),
  (m) => appendTransactionMessageInstruction(transfer, m),
);
const tx = compileTransaction(message);
const messageB64 = getBase64Decoder().decode(tx.messageBytes) as Parameters<typeof rpc.getFeeForMessage>[0];
let fee: bigint | null = null;
try {
  fee = (await rpc.getFeeForMessage(messageB64).send()).value;
} catch (err) {
  warnings.push(`fee read failed: ${err}`);
}
if (fee === null) warnings.push("fee could not be priced");

const account = payerInfo.status === "fulfilled" ? payerInfo.value.value : null;
if (payerInfo.status === "fulfilled") {
  if (!account) warnings.push("payer account does not exist");
  else {
    if (account.owner !== SYSTEM) warnings.push("payer is not a system-owned account, so it cannot pay a fee");
    if (account.lamports < lamports + (fee ?? 0n)) warnings.push("payer balance is below amount plus fee");
  }
}

console.log(JSON.stringify({
  transaction: getBase64EncodedWireTransaction(tx),
  signaturesNeeded: Object.keys(tx.signatures),
  transferAsBuilt: `transfer ${lamports} lamports from ${payer} to ${to}`,
  feeLamports: fee === null ? null : String(fee),
  payerLamports: account ? String(account.lamports) : null,
  lastValidBlockHeight: String(latest.value.value.lastValidBlockHeight),
  currentBlockHeight: height.status === "fulfilled" ? String(height.value) : null,
  warnings,
}, null, 2));
```

Three reads run as settled calls: the latest blockhash, the payer account and the block height. The blockhash is required. A failed account or height read prints a warning and the run continues. All three read at confirmed, the kit's default, so the blockhash comes from a block the cluster has voted on. The account read is `getAccountInfo`, which costs 10 cells.

`compileTransaction` then produces the message with an empty signature slot for the payer, and `getFeeForMessage` prices the message bytes inside a try. When that read fails or returns null, the script prints `feeLamports` as null with a warning, because a printed 0 would tell the signer the transaction is free when it is unpriced.

The output is one JSON object with the base64 transaction, the payer, the transfer as built, the fee, the payer balance and the last valid block height. The transfer line is the script's own description from its arguments, so the signer decodes its own copy of the bytes. Run it with a token mint as the payer and the owner warning appears, because only a system-owned account can pay a fee. The script signs nothing and sends nothing.

## The approval window

A transaction carries a recent blockhash and stays valid for at most 150 blocks. With slots near 200 ms since the Alpenglow switch, that is about 30 seconds from the block the hash came from. A person who has to find a phone and read the screen can miss it. A signer service that approves by policy rarely does.

One way to fit a slow approval is to approve the instructions and rebuild the message with a fresh blockhash just before signing, so the human sees what the transaction does and the clock starts after they say yes. A durable nonce account also works: the transaction uses the nonce value in place of a blockhash, starts with an advance-nonce instruction, and stays valid until that nonce advances.

After signing, the sender submits the transaction with `sendTransaction`, which costs 20 cells without preflight and 70 with it. [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) reads the result back by signature. If the chain height passes the last valid block height with no landed signature, the transaction is dead and a new one must be built and approved again.

## What the signer checks before it signs

- Every program id is on an allowlist, and the instruction layout matches what that program expects.
- The recipient is on a list the operator wrote, or the amount stays under a cap per transaction and per day.
- The fee payer is the signer's own address, and no other account is asked to sign.
- The summary was decoded from the bytes in front of it, and the bytes it signs are those same bytes.
- Enough block height remains to send before expiry.

> A signature approves everything in the message. A second instruction slipped in beside the transfer is signed with it, so the allowlist has to cover every instruction in the message.

Keep the agent's own key apart from all of this. The agent's Carbium key reads chain data and nothing else, which is the layout [Agent RPC key safety](https://carbium.sh/library/si/agent-rpc-key-safety) describes for keeping keys out of prompts and logs.

## Where it ends

- The script builds one kind of transaction, a SOL transfer. A token transfer needs the token program's accounts and instruction layout, and a program call needs that program's own encoding.
- It does not simulate the transaction. The balance check ignores the rent minimum, so a transfer that leaves the payer with a small nonzero balance can still fail.
- The fee comes from the message as built. Priority fee instructions added later change it.
- A base64 string means nothing to a person. The signer needs a wallet or a viewer that decodes it, and the script does not provide one.
- A per-transaction and daily cap limits the damage, but it cannot stop a person from approving a bad request that an injected instruction made look reasonable.

## When it goes wrong

| What goes wrong | What to do |
|---|---|
| The block height passes the last valid block height before the signer answers. | Rebuild with a fresh blockhash after approval, or build against a durable nonce so the transaction does not expire on a clock. |
| The agent describes one transfer and the bytes carry another. | Decode the summary the signer reads from the message bytes it signs. |
| The fee payer is not a system-owned account, or its balance is below the amount plus the fee. | Check the owner and balance before the handoff and refuse it. The script prints both as warnings. |
| An extra instruction rides in the message next to the approved one. | Run every instruction in the message through the program allowlist. |
| The script exits with 401 at the door. | The key was cut short or is unknown. Attach the whole key in `CARBIUM_KEY`. |

## Questions

### Can the agent hold a hot wallet with a small balance instead?

Yes, and a small balance caps the loss. It still holds a key a prompt injection can reach, so keep the balance to an amount you can lose and put a cap in the signer.

### Why not let the model sign inside a tool?

A tool the model calls runs on the model's say-so. Signing in a separate process puts the policy outside the model's reach, where an injected instruction cannot edit it.

### How do I confirm the transaction landed?

Read it back by signature once the signer has sent it. `getTransaction` costs 50 cells, and [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) shows the status check.

### Does the handoff work for a swap?

Yes. The `swap` method returns an unsigned transaction, and the same checks apply before the signer signs it.

## Related

- [Agent RPC key safety](https://carbium.sh/library/si/agent-rpc-key-safety) (AI and blockchain, SI0006)
- [Transaction status check](https://carbium.sh/library/howsolana/transaction-status-check) (How to use Solana, HS0008)
- [carbium.sh/docs#rpc](https://carbium.sh/docs#rpc)
- [carbium.sh/docs#swap](https://carbium.sh/docs#swap)
- [carbium.sh/docs#endpoints](https://carbium.sh/docs#endpoints)
- [carbium.sh/docs#auth](https://carbium.sh/docs#auth)
- [carbium.sh/docs#errors](https://carbium.sh/docs#errors)
