Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(deploy-onchain): mint and register in one atomic v1 transaction when the wallet supports it

nirholasfb01631fc8d3
diff --git a/pages/deploy-onchain.html b/pages/deploy-onchain.html
index 54b0ee754..672891d93 100644
--- a/pages/deploy-onchain.html
+++ b/pages/deploy-onchain.html
@@ -224,6 +224,7 @@
<dl class="do-success-rows">
<div><dt>Core asset</dt><dd><code id="do-out-asset"></code><button type="button" class="do-copy" data-copy="do-out-asset" aria-label="Copy asset address">copy</button></dd></div>
<div><dt>Agent wallet</dt><dd><code id="do-out-wallet"></code><button type="button" class="do-copy" data-copy="do-out-wallet" aria-label="Copy agent wallet">copy</button></dd></div>
+ <div><dt>Transaction</dt><dd id="do-out-format"></dd></div>
</dl>
<div class="do-success-links" id="do-out-links"></div>
<button type="button" class="do-btn do-btn-ghost" id="do-again">Deploy another</button>
diff --git a/src/deploy-onchain.js b/src/deploy-onchain.js
index 02fcbe2ad..8c11041b7 100644
--- a/src/deploy-onchain.js
+++ b/src/deploy-onchain.js
@@ -14,6 +14,11 @@
* create(+register) transaction(s) with the wallet as a noop signer → the
* wallet signs (signAllTransactions) → broadcast IN ORDER through the
* same-origin RPC proxy, absorbing the create→register propagation race.
+ *
+ * When create+register overflow the 1,232-byte v0 limit and the wallet
+ * advertises Solana transaction v1 (Wallet Standard), the mint instead ships as
+ * ONE atomic v1 transaction (4,096 bytes): no second signature, no propagation
+ * race, and no half-deployed asset if registration would fail.
*/
import {
@@ -423,6 +428,50 @@ async function confirmSig(conn, signature) {
throw new Error(`Confirmation timed out for ${signature}. Check the explorer before retrying.`);
}
+/**
+ * Build the whole mint as one partially signed v1 transaction when the split
+ * v0 path would otherwise be needed. Returns null when the wallet cannot sign
+ * v1 or the mint still exceeds the v1 size limit, so the caller keeps the
+ * two-transaction path.
+ */
+async function buildAtomicV1Mint(umi, mint) {
+ if (mint.atomic) return null;
+ const [{ getWallets }, { findV1WalletStandardSigner }, v1] = await Promise.all([
+ import('@wallet-standard/app'),
+ import('./onchain/adapters/solana.js'),
+ import('../api/_lib/solana/transaction-v1.js'),
+ ]);
+ const signer = findV1WalletStandardSigner(getWallets().get(), state.walletAddr);
+ if (!signer) return null;
+ const lifetime = await umi.rpc.getLatestBlockhash({ commitment: 'confirmed' });
+ try {
+ const bytes = await v1.buildPartiallySignedV1Transaction({
+ instructions: mint.combinedBuilder.getInstructions(),
+ signers: mint.combinedBuilder.getSigners(umi),
+ feePayer: state.walletAddr,
+ lifetime,
+ });
+ return { signer, bytes };
+ } catch (err) {
+ if (/exceeds limit of \d+ bytes/i.test(err?.message || '')) return null;
+ throw err;
+ }
+}
+
+async function sendAtomicV1Mint(web3, v1Mint) {
+ const [result] = await v1Mint.signer.feature.signTransaction({
+ account: v1Mint.signer.account,
+ transaction: v1Mint.bytes,
+ options: { preflightCommitment: 'confirmed' },
+ });
+ if (!result?.signedTransaction) throw new Error('The wallet returned no signed transaction.');
+ setStage('mint', ['build', 'sign']);
+ const conn = new web3.Connection(RPC[state.network], 'confirmed');
+ const sig = await conn.sendRawTransaction(result.signedTransaction, { skipPreflight: false });
+ await confirmSig(conn, sig);
+ return sig;
+}
+
async function deploy() {
if (state.deploying || !state.wallet || !state.walletAddr) return;
const p = mintParams();
@@ -451,6 +500,18 @@ async function deploy() {
const mint = mintLib.buildAgentMint(umi, p);
const asset = mint.assetSigner.publicKey.toString();
+ const [agentWalletPda] = coreLib.findAssetSignerPda(umi, { asset: umiLib.publicKey(asset) });
+
+ const v1Mint = await buildAtomicV1Mint(umi, mint);
+ if (v1Mint) {
+ setStage('sign', ['build']);
+ const sig = await sendAtomicV1Mint(web3, v1Mint);
+ setStage('live', ['build', 'sign', 'mint', 'register']);
+ showSuccess({ asset, signatures: [sig], agentWallet: agentWalletPda.toString(), transactionVersion: 1 });
+ refreshBalance();
+ loadLatest();
+ return;
+ }
const built = [];
for (const builder of mint.builders) built.push(await builder.buildAndSign(umi));
@@ -501,8 +562,7 @@ async function deploy() {
}
setStage('live', ['build', 'sign', 'mint', 'register']);
- const [agentWalletPda] = coreLib.findAssetSignerPda(umi, { asset: umiLib.publicKey(asset) });
- showSuccess({ asset, signatures, agentWallet: agentWalletPda.toString() });
+ showSuccess({ asset, signatures, agentWallet: agentWalletPda.toString(), transactionVersion: 0 });
refreshBalance();
loadLatest();
} catch (err) {
@@ -523,8 +583,14 @@ function friendlyError(err) {
return `Deploy failed: ${msg}`;
}
-function showSuccess({ asset, signatures, agentWallet }) {
+function showSuccess({ asset, signatures, agentWallet, transactionVersion }) {
$('do-out-asset').textContent = asset;
+ $('do-out-format').textContent =
+ transactionVersion === 1
+ ? 'Minted and registered atomically in one Solana v1 transaction'
+ : signatures.length > 1
+ ? 'Minted, then registered, in two transactions'
+ : 'Minted and registered atomically in one transaction';
$('do-out-wallet').textContent = agentWallet || 'derived on first read (see the agent page)';
const dev = state.network === 'devnet';
const links = [
diff --git a/tests/transaction-v1.test.js b/tests/transaction-v1.test.js
index 2555f6092..a0a05afb3 100644
--- a/tests/transaction-v1.test.js
+++ b/tests/transaction-v1.test.js
@@ -11,6 +11,12 @@ import {
} from '../api/_lib/solana/transaction-v1.js';
import { cosignV1Transaction } from '../src/erc8004/solana-deploy.js';
import { getTransactionDecoder } from '@solana/kit';
+import bs58 from 'bs58';
+import { createUmi } from '@metaplex-foundation/umi-bundle-defaults';
+import { mplCore } from '@metaplex-foundation/mpl-core';
+import { mplAgentIdentity } from '@metaplex-foundation/mpl-agent-registry';
+import { createNoopSigner, publicKey as umiPublicKey, signerIdentity } from '@metaplex-foundation/umi';
+import { buildAgentMint } from '../packages/metaplex-agent-mcp/src/lib/mint.js';
function signedLegacyTransfer() {
const payer = Keypair.generate();
@@ -146,6 +152,38 @@ describe('Solana transaction V1 inspector', () => {
await expect(cosignV1Transaction(wire, Keypair.generate().secretKey)).rejects.toThrow();
});
+ it('fits a Genesis-shape create+register mint, too big for v0, into one v1 transaction', async () => {
+ const umi = createUmi('http://127.0.0.1:1').use(mplCore()).use(mplAgentIdentity());
+ const wallet = Keypair.generate().publicKey.toBase58();
+ umi.use(signerIdentity(createNoopSigner(umiPublicKey(wallet))));
+ const mint = buildAgentMint(umi, {
+ network: 'devnet',
+ creator: wallet,
+ name: 'Genesis Shape Agent',
+ description: 'd'.repeat(280),
+ image: 'https://three.ws/api/avatars/0f7a2c1e-8b1d-4b8e-9a51-5c7e3d2a9f10/thumbnail.webp',
+ modelUrl: 'https://three.ws/api/avatars/0f7a2c1e-8b1d-4b8e-9a51-5c7e3d2a9f10/model.glb',
+ externalUrl: 'https://three.ws/agents/0f7a2c1e-8b1d-4b8e-9a51-5c7e3d2a9f10',
+ });
+ expect(mint.atomic).toBe(false);
+
+ const wire = await buildPartiallySignedV1Transaction({
+ instructions: mint.combinedBuilder.getInstructions(),
+ signers: mint.combinedBuilder.getSigners(umi),
+ feePayer: wallet,
+ lifetime: { blockhash: Keypair.generate().publicKey.toBase58(), lastValidBlockHeight: 1 },
+ });
+ const inspected = inspectWireTransaction(Buffer.from(wire).toString('base64'));
+ expect(inspected.version).toBe(1);
+ expect(inspected.bytes).toBeGreaterThan(LEGACY_TRANSACTION_LIMIT);
+ expect(inspected.bytes).toBeLessThanOrEqual(V1_TRANSACTION_LIMIT);
+
+ const decoded = getTransactionDecoder().decode(wire);
+ const asset = mint.assetSigner.publicKey.toString();
+ expect(nacl.sign.detached.verify(decoded.messageBytes, decoded.signatures[asset], bs58.decode(asset))).toBe(true);
+ expect(decoded.signatures[wallet]).toBeNull();
+ });
+
it('rejects malformed wire input without contacting an RPC', () => {
expect(() => inspectWireTransaction('not base64!')).toThrow(/base64-encoded/);
expect(() => inspectWireTransaction(Buffer.from('not a transaction').toString('base64'))).toThrow(/valid signed/);