Rent Reclaim, one of the tools on our site, closes a wallet's empty token accounts and gives back the rent they hold. A run is a few transactions of up to 20 closes each, signed in one wallet prompt. In October, Phantom showed this when we ran it:

This dApp could be malicious. Do not proceed unless you are certain it is safe.

Phantom's developer docs say the warning appears when Phantom can't simulate a transaction well enough to predict what it will do. They list five things a dApp can change: send v1 transactions with the compute and loaded-data limits set in the message, sign with signTransaction and send through your own RPC with preflight on, keep to one signer, stay well under the size limit, and simulate with sigVerify: false before asking for a signature. We already did the last four. The first meant moving to a transaction format that went live on mainnet in September and that our transaction library can read but not write.

Whether the warning shows is Phantom's decision in the end, and they also review domains by hand. This post covers the transaction side, the part a dApp controls. Three things broke along the way, and none of them showed up in Node or on a local validator. Then Phantom's support read our code and asked for a few more changes, which are at the end.

What v1 changes

SIMD-0385 defines the new layout. Compared with legacy and v0 transactions:

  • Byte 0 is 0x81, the version tag, so a reader knows the format before parsing anything else.
  • The signatures move to the end, with no length prefix. The header already says how many there are.
  • The compute unit limit, the loaded accounts data limit and the priority fee move out of ComputeBudget instructions into fixed-width fields in the message. A u32 bitmask says which ones are present.
  • The size limit goes from 1,232 bytes to 4,096, and there are no address lookup tables.

The priority fee field is a total in lamports. With SetComputeUnitPrice you set a price per compute unit, and the fee grows with the limit. In v1 the limit and the fee don't depend on each other.

Taking the limits out of instructions also saves space. A single SOL transfer with a compute limit, a loaded-data limit and a priority fee is 275 bytes as a legacy transaction (three ComputeBudget instructions and the ComputeBudget program's address) and 236 bytes as v1.

Writing v1 with web3.js 1.x

We're on @solana/web3.js 1.99. It reads v1 (VersionedTransaction.deserialize returns a MessageV1) but has no way to write one. @solana/kit can, but switching would have meant rewriting every transaction builder in the app. Since the reader was there, our first version was a serializer that mirrors it. web3.js still compiled the message, which orders the accounts and builds the header, and we laid the bytes out in v1 order:

const u32 = (n) => { const b = Buffer.alloc(4); b.writeUInt32LE(n); return b; }; function messageV1(payer, blockhash, instructions, { units, loadedBytes, priorityLamports }) { const m = new TransactionMessage({ payerKey: payer, recentBlockhash: blockhash, instructions }).compileToLegacyMessage(); const ixs = m.compiledInstructions; const { numRequiredSignatures, numReadonlySignedAccounts, numReadonlyUnsignedAccounts } = m.header; return Buffer.concat([ Buffer.from([0x81, numRequiredSignatures, numReadonlySignedAccounts, numReadonlyUnsignedAccounts]), // Config mask: bits 0 and 1 the priority fee (a u64, so both or neither), // bit 2 the compute unit limit, bit 3 the loaded accounts data limit. u32((priorityLamports ? 0b11 : 0) | 0b100 | 0b1000), Buffer.from(bs58.decode(blockhash)), Buffer.from([ixs.length, m.accountKeys.length]), ...m.accountKeys.map((k) => k.toBuffer()), ...(priorityLamports ? [u32(priorityLamports % 2 ** 32), u32(Math.floor(priorityLamports / 2 ** 32))] : []), u32(units), u32(loadedBytes), // Every instruction's header first, then every instruction's accounts and data. ...ixs.map((ix) => { const head = Buffer.alloc(4); head.writeUInt8(ix.programIdIndex, 0); head.writeUInt8(ix.accountKeyIndexes.length, 1); head.writeUInt16LE(ix.data.length, 2); return head; }), ...ixs.map((ix) => Buffer.concat([Buffer.from(ix.accountKeyIndexes), Buffer.from(ix.data)])), ]); } // One signer: the message, then 64 empty bytes for the wallet to sign into. const tx = new Uint8Array(Buffer.concat([messageV1(payer, blockhash, instructions, limits), Buffer.alloc(64)])); 

We checked it by reading its output back with web3.js's own reader and by landing transactions built with it on devnet. It ran in production for a few weeks. We've since replaced it with kit's builder (more on that at the end), but if you only need a handful of v1 transactions out of a web3.js 1.x app, this is all it takes.

The wallet gets the raw bytes through the Wallet Standard solana:signTransaction feature and returns signed bytes, which web3.js 1.x can't turn back into an object it can serialize. So a v1 transaction stays a Uint8Array from build to sendRawTransaction.

Which wallets get v1

Wallets list the transaction versions they sign in supportedTransactionVersions on that same feature. Solana's migration notes check the list for 1, and so do we:

function signsV1(wallet) { const standard = wallet.wallet?.adapter?.wallet; const feature = standard?.features?.["solana:signTransaction"]; const account = standard?.accounts?.find((a) => a.address === wallet.publicKey?.toBase58()); return !!( feature?.supportedTransactionVersions?.includes(1) && account?.features?.includes("solana:signTransaction") && !unreadableV1.has(standard.name) ); } 

Our first version also let Phantom in by name, since its docs ask dApps for v1. That was a mistake, and the second problem below shows why: the same wallet name can sit on top of different code on another platform. The name check is gone. The unreadableV1 set comes from that same problem. Every wallet that doesn't pass gets a legacy transaction with the same limits set by ComputeBudget instructions.

Setting the limits from a dry run

With v1 the limits are part of the signed message, so they have to be chosen before the wallet sees it. We build a draft with the largest values (1,400,000 compute units and 64 MiB of loaded data), simulate it, and read two numbers from the result:

const res = await connection._rpcRequest("simulateTransaction", [ Buffer.from(draft).toString("base64"), { encoding: "base64", sigVerify: false, replaceRecentBlockhash: true, commitment: "confirmed" }, ]); const { err, unitsConsumed, loadedAccountsDataSize } = res.result.value; 

The draft goes through the raw RPC method because web3.js's simulateTransaction wants a transaction object it can serialize. replaceRecentBlockhash means the draft can carry any 32 bytes as its blockhash, which becomes useful in the third problem.

Our first version set unitsConsumed × 1.3 + 10,000 units and loadedAccountsDataSize × 1.1 + 32 KiB of loaded data. Transactions with those limits landed on devnet without trouble. Phantom still showed the warning.

Problem 1: no room for the wallet's own instructions

Phantom adds instructions of its own before it signs. They call Lighthouse (L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95), an assertion program: the added instructions check that accounts end up the way the simulation showed and fail the transaction if they don't. That protects the user. It also means the transaction Phantom simulates isn't quite the one we built, and it has to fit under the limits we set.

The loaded-data limit counts the code of every program a transaction calls, and Lighthouse's program data account is 424,293 bytes. One of our close batches loaded about 820 KB in the dry run, so its limit came out at 935,950 bytes. With Lighthouse added, the same transaction needs about 1.25 MB. The guarded transaction couldn't fit under our limit, so Phantom's simulation of it would fail, and a transaction Phantom can't simulate is exactly what the warning is for.

Phantom's own v1 example gives a plain SOL transfer, which uses about 150 compute units, a limit of 200,000 units and 1 MiB of loaded data. We now add that much on top of the dry run:

const WALLET_UNITS_ROOM = 200_000; const WALLET_LOADED_ROOM = 1024 * 1024; const expected = Math.ceil(unitsConsumed * 1.3) + 10_000; const units = Math.min(1_400_000, expected + WALLET_UNITS_ROOM); const loadedBytes = Math.min(64 * 1024 * 1024, Math.ceil(loadedAccountsDataSize * 1.1) + WALLET_LOADED_ROOM); 

The same batch now goes out with limits of 214,288 units and 1,951,758 bytes. In v1 the higher compute limit costs nothing, because the priority fee is a fixed total. In the legacy fallback the fee is a price per unit of the limit, so we divide the total we want by the limit and the fee comes out the same.

Problem 2: Phantom on Android couldn't read v1

Rent Reclaim logs each step of a run with its error text. A week after the change, the log showed a Phantom user on Android, in Phantom's in-app browser, fail twice in a row one second after tapping Confirm, before any wallet prompt appeared:

Reached end of buffer unexpectedly 

That message comes from web3.js's byte reader, and the cause is the first byte. Legacy and v0 transactions start with their signature count as a compact-u16, a variable-length integer that uses the top bit of each byte to say another byte follows. A reader that doesn't know v1 takes 0x81 as the start of that number: the low seven bits are 1 and the top bit is set, so it reads the next byte as well. The next byte is the header's signature count, 1. That makes 1 + (1 << 7) = 129 signatures, or 8,256 bytes of them, in a 236-byte transaction.

It reproduces with an older web3.js:

// @solana/web3.js 1.99.0 VersionedTransaction.deserialize(v1Bytes).version; // 1 // @solana/web3.js 1.95.8 VersionedTransaction.deserialize(v1Bytes); // Error: Reached end of buffer unexpectedly Transaction.from(v1Bytes); // Error: Reached end of buffer unexpectedly 

Desktop Phantom read v1 without trouble at the time, so one wallet name meant two readers. That's why the name check above had to go. In November we saw Phantom on a phone sign a v1 transaction, so newer app builds do read it, but we can't tell which build a visitor has. So we still fall back when it happens.

signBuilt takes a function that builds the transactions instead of the transactions themselves. If a v1 batch throws one of these errors, it marks the wallet for the rest of the visit and builds again, and the second build comes out legacy because signsV1 now answers no:

const V1_UNREADABLE = /end of buffer|version 1|deserializ/i; async function signBuilt(connection, wallet, build) { const txs = build(); try { return await signAllForNetwork(connection, wallet, txs); } catch (e) { if (!txs.some((tx) => tx instanceof Uint8Array) || !V1_UNREADABLE.test(e.message)) throw e; unreadableV1.add(wallet.wallet?.adapter?.wallet?.name); return signAllForNetwork(connection, wallet, build()); } } 

The error comes before the prompt, so the user still sees one approval. The legacy build carries the same limits as ComputeBudget instructions. web3.js 1.x has helpers for the compute limit and price but none for the loaded-data limit, which is ComputeBudget instruction 4 followed by a u32:

function setLoadedAccountsDataSizeLimit(bytes) { const data = Buffer.alloc(5); data.writeUInt8(4, 0); data.writeUInt32LE(bytes, 1); return new TransactionInstruction({ programId: ComputeBudgetProgram.programId, keys: [], data }); } 

We tested the fallback with a mock wallet that reads transactions through web3.js 1.95.8. The first attempt failed before any prompt, the rebuilt legacy batch went through, and 35 accounts closed.

Problem 3: a blockhash lasts about 30 seconds now

With the fallback live, the same user's next run failed in a new way. The approval came back after 37 seconds, and none of the three signed transactions could be sent because their blockhash had expired.

A transaction is valid for 150 blocks after its blockhash. That used to be about a minute. Slots on mainnet went to 200 ms in October, and when we measured on 30 October the chain produced 4.56 blocks per second, so 150 blocks is about 33 seconds. A user who reads the prompt carefully on a phone can use most of that.

We made two changes. First, everything slow now happens before the blockhash is fetched. Quotes and dry runs come first (the dry run doesn't need a real blockhash, thanks to replaceRecentBlockhash), so the whole 30 seconds belong to the user. Second, when a send fails with "blockhash not found", we check the block height before doing anything else:

async function sendSigned(connection, tx, blockhash, lastValidBlockHeight) { for (let attempt = 1; ; attempt += 1) { try { return await connection.sendRawTransaction(tx, { skipPreflight: false }); } catch (e) { if (!/blockhash not found/i.test(e.message)) throw e; const height = await connection.getBlockHeight("confirmed").catch(() => null); if (height != null && height > lastValidBlockHeight) throw Object.assign(e, { expired: true }); if (attempt >= 4) throw e; await new Promise((r) => setTimeout(r, 1000)); } } } 

Below lastValidBlockHeight, the RPC node may not have seen the blockhash yet, so the same signed bytes go out again a second later. Past it, the signed transaction can never land, and only then is it safe to ask for a new signature. The unsent transactions are built again with a fresh blockhash and the wallet is asked once more, at most twice per run, with a line telling the user why. The order matters: asking for a new signature while the old one could still land is how a transaction ends up executing twice.

What Phantom's support asked for

We sent Phantom the code above. Their support team came back with a list of requests. Dropping the name check was one of them. These are the others.

Use the builder from their example

Phantom's v1 example builds with @solana/kit 8.3. Our hand-written serializer produced valid v1 of the same size, but it's easier for a reviewer to trust bytes that come out of the builder their own example uses. The app couldn't move to kit 8 outright, because Orca's Whirlpool client pins kit 5. So kit 8 is installed a second time under an npm alias and loaded only when the first v1 transaction is built:

// package.json: "solana-kit-8": "npm:@solana/kit@8.3.0" let kitLoading = null; const loadKit = () => { if (!kitLoading) kitLoading = import("solana-kit-8"); return kitLoading; }; function transactionV1(kit, payer, blockhash, lastValidBlockHeight, instructions, { units, loadedBytes, priorityLamports }) { const message = kit.pipe( kit.createTransactionMessage({ version: 1 }), (m) => kit.setTransactionMessageFeePayer(kit.address(payer.toBase58()), m), (m) => kit.setTransactionMessageLifetimeUsingBlockhash({ blockhash, lastValidBlockHeight: BigInt(lastValidBlockHeight || 0) }, m), (m) => kit.setTransactionMessageConfig( { computeUnitLimit: units, loadedAccountsDataSizeLimit: loadedBytes, ...(priorityLamports ? { priorityFeeLamports: BigInt(priorityLamports) } : {}), }, m ), (m) => kit.appendTransactionMessageInstructions( instructions.map((ix) => ({ programAddress: kit.address(ix.programId.toBase58()), accounts: ix.keys.map((k) => ({ address: kit.address(k.pubkey.toBase58()), role: roleOf(kit, k) })), data: new Uint8Array(ix.data), })), m ) ); return new Uint8Array(kit.getTransactionEncoder().encode(kit.compileTransaction(message))); } 

The instructions are still web3.js TransactionInstruction objects, so no builder elsewhere in the app changed. roleOf maps isSigner and isWritable to kit's four account roles. Webpack puts kit 8 in its own chunk of about 56 KB gzipped, and a visitor whose wallet doesn't list v1 never downloads it. One difference from our serializer: kit sorts the accounts inside each role, where web3.js keeps the order they were first seen in. Both are valid.

Dry-run the transaction you'll sign

We simulated a draft with maximum limits and then applied the measured ones. Now there's a second dry run with the final limits in place, so the only thing that changes between the last simulation and the prompt is the blockhash.

Don't assume the wallet signs your blockhash

A wallet may put a fresher blockhash in as it signs. If it does, our lastValidBlockHeight running out proves nothing about the transaction that was signed, and the expiry check in problem 3 could re-ask while the first signature is still able to land. So the blockhash is read back out of the signed bytes, and when it isn't ours, the bound moves:

async function lifetimeOf(connection, sent, signed) { if (blockhashOf(signed) === sent.blockhash) return sent; const height = await connection.getBlockHeight("confirmed").catch(() => null); return { blockhash: blockhashOf(signed), lastValidBlockHeight: Math.max(sent.lastValidBlockHeight, (height ?? sent.lastValidBlockHeight) + 150 + 10), }; } 

Any blockhash the wallet fetched before it answered expires within 150 blocks of the height we read now. The extra 10 covers a wallet whose RPC runs a little ahead of ours. We tested it with a mock wallet that answered after 73 seconds carrying a refreshed blockhash. It landed, and nothing was asked for twice.

Without v1, stay near 900 bytes

The wallet's guard instructions need room in a 1,232-byte legacy transaction too. Rent Reclaim now puts 20 closes in a v1 transaction and 16 in a legacy one, which comes to about 840 bytes.

Do those changes make the warning go away? We don't know yet, and it isn't ours to say. What we can say is that one run on a phone in November had two legacy transactions with a second signer, which Phantom warned on, followed by a v1 transaction, which it didn't. Since then the two-signer ones go out as v1 as well, with the wallet signing first.

If you're about to make the same move, most of what bit us comes down to two habits. Leave the wallet room in every limit you set, because the transaction it simulates is bigger than the one you built. And keep a legacy path with the same limits that you can switch to on the wallet's own error, since a wallet that signs v1 on one platform can fail on another.

All of this runs in Rent Reclaim, which c...