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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat: add on-chain publishing functionality with ERC-8004 support
nirholas0a6661495ced
diff --git a/character-studio/src/library/characterManager.js b/character-studio/src/library/characterManager.jsindex 10386e313..fce7d0c9c 100644--- a/character-studio/src/library/characterManager.js+++ b/character-studio/src/library/characterManager.js@@ -163,6 +163,9 @@ export class CharacterManager {getLoadedManifests(){return this.manifestDataManager.getLoadedManifests();}+ getManifestURL(){+ return this.manifestDataManager.getMainManifestURL();+ }/*** Adds look-at mouse behavior to the character.diff --git a/character-studio/src/library/erc8004.js b/character-studio/src/library/erc8004.jsnew file mode 100644index 000000000..bfc180c7d--- /dev/null+++ b/character-studio/src/library/erc8004.js@@ -0,0 +1,161 @@+/**+ * Minimal ERC-8004 helpers for the character studio.+ * Handles wallet connection, IPFS pinning, and on-chain registration.+ */++import { BrowserProvider, Contract } from 'ethers';++const IDENTITY_REGISTRY_ABI = [+ 'function register(string agentURI) external returns (uint256 agentId)',+ 'function setAgentURI(uint256 agentId, string newURI) external',+ 'event Registered(uint256 indexed agentId, string agentURI, address indexed owner)',+];++const TESTNET_REGISTRY = '0x8004A818BFB912233c491871b3d84c89A494BD9e';+const MAINNET_REGISTRY = '0x8004A169FB4a3325136EB29fA0ceB6D2e539a432';++const TESTNET_CHAIN_IDS = new Set([97, 11155111, 84532, 421614, 11155420, 80002, 43113]);++const SUPPORTED_CHAINS = {+ 1: { name: 'Ethereum', registry: MAINNET_REGISTRY },+ 10: { name: 'Optimism', registry: MAINNET_REGISTRY },+ 137: { name: 'Polygon', registry: MAINNET_REGISTRY },+ 8453: { name: 'Base', registry: MAINNET_REGISTRY },+ 42161: { name: 'Arbitrum One', registry: MAINNET_REGISTRY },+ 43114: { name: 'Avalanche', registry: MAINNET_REGISTRY },+ 11155111: { name: 'Ethereum Sepolia', registry: TESTNET_REGISTRY },+ 84532: { name: 'Base Sepolia', registry: TESTNET_REGISTRY },+ 421614: { name: 'Arbitrum Sepolia', registry: TESTNET_REGISTRY },+ 80002: { name: 'Polygon Amoy', registry: TESTNET_REGISTRY },+};++export function getSupportedChains() {+ return SUPPORTED_CHAINS;+}++export function getRegistryAddress(chainId) {+ return SUPPORTED_CHAINS[chainId]?.registry ?? null;+}++// ---------------------------------------------------------------------------+// Wallet+// ---------------------------------------------------------------------------++export async function connectWallet() {+ if (!window.ethereum) throw new Error('No wallet detected. Install MetaMask to continue.');+ const provider = new BrowserProvider(window.ethereum);+ const signer = await provider.getSigner();+ const address = await signer.getAddress();+ const network = await provider.getNetwork();+ const chainId = Number(network.chainId);+ return { provider, signer, address, chainId };+}++// ---------------------------------------------------------------------------+// IPFS pinning via Pinata+// ---------------------------------------------------------------------------++async function pinJSON(obj, pinataJWT) {+ if (!pinataJWT) throw new Error('A Pinata JWT is required to pin files to IPFS.');+ const blob = new Blob([JSON.stringify(obj, null, 2)], { type: 'application/json' });+ const form = new FormData();+ form.append('file', blob, 'manifest.json');+ const res = await fetch('https://api.pinata.cloud/pinning/pinFileToIPFS', {+ method: 'POST',+ headers: { Authorization: `Bearer ${pinataJWT}` },+ body: form,+ });+ if (!res.ok) {+ const text = await res.text().catch(() => res.status);+ throw new Error(`Pinata upload failed (${res.status}): ${text}`);+ }+ const data = await res.json();+ return `ipfs://${data.IpfsHash}`;+}++// ---------------------------------------------------------------------------+// Registration JSON builder+// ---------------------------------------------------------------------------++function buildRegistrationJSON({ name, manifestURL, agentId, chainId, registryAddr }) {+ return {+ type: 'https://eips.ethereum.org/EIPS/eip-8004#registration-v1',+ name: name || 'Character',+ description: `VRM character studio manifest`,+ active: true,+ services: [+ {+ name: 'vrm-manifest',+ endpoint: manifestURL,+ version: '1.0',+ },+ ],+ registrations: [+ {+ agentId,+ agentRegistry: `eip155:${chainId}:${registryAddr}`,+ },+ ],+ supportedTrust: ['reputation'],+ };+}++// ---------------------------------------------------------------------------+// Full registration flow+// ---------------------------------------------------------------------------++/**+ * @param {object} opts+ * @param {string} opts.name Display name for the on-chain token+ * @param {string} opts.manifestURL URL of the VRM character manifest JSON+ * @param {string} opts.pinataJWT Pinata API JWT for IPFS pinning+ * @param {(msg: string) => void} opts.onStatus Progress callback+ * @returns {Promise<{ agentId: number, txHash: string, chainId: number, registrationURL: string }>}+ */+export async function registerCharacterOnChain({ name, manifestURL, pinataJWT, onStatus }) {+ const log = onStatus || (() => {});++ log('Connecting wallet…');+ const { signer, chainId } = await connectWallet();++ const registryAddr = getRegistryAddress(chainId);+ if (!registryAddr) {+ throw new Error(+ `Chain ${chainId} is not supported. Switch to one of: ${Object.values(SUPPORTED_CHAINS)+ .map((c) => c.name)+ .join(', ')}.`+ );+ }++ const registry = new Contract(registryAddr, IDENTITY_REGISTRY_ABI, signer);++ log('Registering on-chain…');+ const tx = await registry['register(string)'](manifestURL);+ log(`Transaction submitted: ${tx.hash}`);+ const receipt = await tx.wait();++ let agentId = null;+ for (const log_ of receipt.logs) {+ try {+ const parsed = registry.interface.parseLog(log_);+ if (parsed?.name === 'Registered') {+ agentId = Number(parsed.args.agentId);+ break;+ }+ } catch { /* not our event */ }+ }+ if (agentId == null) throw new Error('Registered event not found in receipt.');+ log(`Minted agentId = ${agentId}`);++ log('Pinning registration metadata to IPFS…');+ const registrationJSON = buildRegistrationJSON({ name, manifestURL, agentId, chainId, registryAddr });+ const registrationURL = await pinJSON(registrationJSON, pinataJWT);+ log(`Pinned: ${registrationURL}`);++ log('Updating agentURI on-chain…');+ const updateTx = await registry.setAgentURI(agentId, registrationURL);+ await updateTx.wait();+ log('Done.');++ return { agentId, txHash: tx.hash, chainId, registrationURL };+}diff --git a/character-studio/src/library/manifestDataManager.js b/character-studio/src/library/manifestDataManager.jsindex 5925beecd..f78d5bd9e 100644--- a/character-studio/src/library/manifestDataManager.js+++ b/character-studio/src/library/manifestDataManager.js@@ -6,12 +6,17 @@ export class ManifestDataManager{this.mainManifestData = null;this.manifestDataCollection = [];this.manifestDataByIdentifier = {};+ this._mainManifestURL = null;this.defaultValues = {defaultCullingLayer:-1,defaultCullingDistance:null,maxCullingDistance:Infinity};-++ }++ getMainManifestURL(){+ return this._mainManifestURL;}getLoadedLockedManifests(isLocked){return this.manifestDataCollection.filter((manifestData)=>manifestData.locked == isLocked);@@ -126,6 +131,7 @@ export class ManifestDataManager{try {// Fetch the manifest data asynchronouslythis._fetchManifest(url).then(manifest=>{+ if (this._mainManifestURL == null) this._mainManifestURL = url;this.setManifest(manifest, identifier).then(()=>{resolve();})diff --git a/character-studio/src/pages/OnChainPublish.jsx b/character-studio/src/pages/OnChainPublish.jsxnew file mode 100644index 000000000..63bfb8e94--- /dev/null+++ b/character-studio/src/pages/OnChainPublish.jsx@@ -0,0 +1,119 @@+import React, { useContext, useState } from 'react';+import { SceneContext } from '../context/SceneContext';+import { registerCharacterOnChain, getSupportedChains } from '../library/erc8004';+import styles from './OnChainPublish.module.css';++const PINATA_JWT_KEY = 'characterstudio:pinata-jwt';++function loadSavedJWT() {+ try { return localStorage.getItem(PINATA_JWT_KEY) || ''; }+ catch { return ''; }+}+function saveJWT(jwt) {+ try { if (jwt) localStorage.setItem(PINATA_JWT_KEY, jwt); else localStorage.removeItem(PINATA_JWT_KEY); }+ catch { /* storage disabled */ }+}++export default function OnChainPublish({ onClose }) {+ const { characterManager } = useContext(SceneContext);+ const [pinataJWT, setPinataJWT] = useState(loadSavedJWT);+ const [status, setStatus] = useState('');+ const [result, setResult] = useState(null);+ const [error, setError] = useState('');+ const [busy, setBusy] = useState(false);++ const manifestURL = characterManager?.getManifestURL?.() || '';+ const chains = getSupportedChains();++ async function handlePublish() {+ setError('');+ setResult(null);+ setStatus('');+ if (!manifestURL) { setError('No manifest loaded — open a character collection first.'); return; }+ if (!pinataJWT.trim()) { setError('Enter your Pinata JWT to pin files to IPFS.'); return; }+ saveJWT(pinataJWT.trim());+ setBusy(true);+ try {+ const r = await registerCharacterOnChain({+ name: 'Character Studio Manifest',+ manifestURL,+ pinataJWT: pinataJWT.trim(),+ onStatus: setStatus,+ });+ setResult(r);+ } catch (err) {+ setError(err.message || 'Unknown error');+ } finally {+ setBusy(false);+ }+ }++ const chainNames = Object.values(chains).map((c) => c.name).join(', ');++ return (+ <div className={styles.overlay}>+ <div className={styles.modal}>+ <div className={styles.header}>+ <span className={styles.title}>Publish on-chain</span>+ <button className={styles.close} onClick={onClose} aria-label="Close">✕</button>+ </div>++ {!result ? (+ <>+ <p className={styles.description}>+ Mint an ERC-8004 token on-chain pointing to this character manifest.+ The token links to: <code className={styles.url}>{manifestURL || '(no manifest loaded)'}</code>+ </p>++ <label className={styles.label}>+ Pinata JWT+ <input+ className={styles.input}+ type="password"+ placeholder="eyJhbGci…"+ value={pinataJWT}+ onChange={(e) => setPinataJWT(e.target.value)}+ disabled={busy}+ />+ <span className={styles.hint}>+ Used to pin the registration JSON to IPFS.{' '}+ <a href="https://app.pinata.cloud/keys" target="_blank" rel="noopener noreferrer">+ Get a key →+ </a>+ </span>+ </label>++ <p className={styles.hint}>+ Supported chains: {chainNames}.<br />+ Switch your wallet to any of these before clicking Publish.+ </p>++ {status && <p className={styles.status}>{status}</p>}+ {error && <p className={styles.error}>{error}</p>}++ <div className={styles.actions}>+ <button className={styles.cancelBtn} onClick={onClose} disabled={busy}>Cancel</button>+ <button className={styles.publishBtn} onClick={handlePublish} disabled={busy || !manifestURL}>+ {busy ? 'Publishing…' : '⬡ Publish on-chain'}+ </button>+ </div>+ </>+ ) : (+ <div className={styles.success}>+ <div className={styles.successIcon}>✓</div>+ <p>Minted on-chain!</p>+ <p>Agent ID: <strong>{result.agentId}</strong></p>+ <p>Chain: <strong>{result.chainId}</strong></p>+ <p className={styles.txHash}>+ Tx: <code>{result.txHash.slice(0, 18)}…</code>+ </p>+ <p className={styles.hint}>+ Registration: <code>{result.registrationURL}</code>+ </p>+ <button className={styles.publishBtn} onClick={onClose}>Close</button>+ </div>+ )}+ </div>+ </div>+ );+}diff --git a/character-studio/src/pages/OnChainPublish.module.css b/character-studio/src/pages/OnChainPublish.module.cssnew file mode 100644index 000000000..63e26f10a--- /dev/null+++ b/character-studio/src/pages/OnChainPublish.module.css@@ -0,0 +1,148 @@+.overlay {+ position: fixed;+ inset: 0;+ background: rgba(0, 0, 0, 0.65);+ display: flex;+ align-items: center;+ justify-content: center;+ z-index: 1000;+}++.modal {+ background: #1a1a2e;+ border: 1px solid #333;+ border-radius: 10px;+ padding: 24px;+ width: 460px;+ max-width: 96vw;+ color: #eee;+ font-size: 14px;+}++.header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ margin-bottom: 16px;+}++.title {+ font-size: 16px;+ font-weight: 600;+ color: #fff;+}++.close {+ background: none;+ border: none;+ color: #aaa;+ font-size: 18px;+ cursor: pointer;+ line-height: 1;+ padding: 0 4px;+}+.close:hover { color: #fff; }++.description {+ margin-bottom: 16px;+ line-height: 1.5;+ color: #ccc;+}++.url {+ display: block;+ margin-top: 6px;+ font-size: 11px;+ color: #8ba6ff;+ word-break: break-all;+}++.label {+ display: flex;+ flex-direction: column;+ gap: 6px;+ margin-bottom: 14px;+ font-size: 13px;+ color: #ddd;+}++.input {+ background: #0d0d1a;+ border: 1px solid #444;+ border-radius: 6px;+ color: #eee;+ font-size: 13px;+ padding: 8px 10px;+ outline: none;+}+.input:focus { border-color: #6c8fff; }+.input:disabled { opacity: 0.5; }++.hint {+ font-size: 11px;+ color: #888;+ line-height: 1.4;+}+.hint a { color: #8ba6ff; }++.status {+ font-size: 12px;+ color: #adf;+ margin: 8px 0;+ font-family: monospace;+}++.error {+ color: #f88;+ font-size: 13px;+ margin: 8px 0;+}++.actions {+ display: flex;+ justify-content: flex-end;+ gap: 10px;+ margin-top: 20px;+}++.cancelBtn {+ background: transparent;+ border: 1px solid #444;+ color: #ccc;+ border-radius: 6px;+ padding: 8px 16px;+ cursor: pointer;+ font-size: 13px;+}+.cancelBtn:hover { border-color: #777; color: #fff; }+.cancelBtn:disabled { opacity: 0.4; cursor: default; }++.publishBtn {+ background: #3a5fc8;+ border: none;+ color: #fff;+ border-radius: 6px;+ padding: 8px 18px;+ cursor: pointer;+ font-size: 13px;+ font-weight: 600;+}+.publishBtn:hover { background: #4d72e0; }+.publishBtn:disabled { opacity: 0.4; cursor: default; }++.success {+ text-align: center;+ padding: 12px 0;+ line-height: 1.8;+}++.successIcon {+ font-size: 40px;+ color: #5cf87a;+ margin-bottom: 8px;+}++.txHash {+ font-size: 12px;+ color: #aaa;+}diff --git a/character-studio/src/pages/Save.jsx b/character-studio/src/pages/Save.jsxindex 870b0365a..e41a20676 100644--- a/character-studio/src/pages/Save.jsx+++ b/character-studio/src/pages/Save.jsx@@ -11,6 +11,7 @@ import MessageWindow from "../components/MessageWindow"import MergeOptions from "../components/MergeOptions"import FileDropComponent from "../components/FileDropComponent"import PurchaseMenu from "../components/PurchaseMenu"+import OnChainPublish from "./OnChainPublish"function Save() {@@ -25,6 +26,7 @@ function Save() {const [confirmDialogWindow, setConfirmDialogWindow] = useState(false)const [dialogMessage, setDialogMessage] = useState("")+ const [showOnChainPublish, setShowOnChainPublish] = useState(false)const [currentPrice, setCurrentPrice] = React.useState(0)const [purchaseTraits, setPurchaseTraits] = React.useState([])@@ -105,6 +107,13 @@ function Save() {onPurchaseClick = {onPurchaseClick}/>+ <CustomButton+ theme="light"+ text="⬡ On-chain"+ size={14}+ className={styles.buttonCenter}+ onClick={() => setShowOnChainPublish(true)}+ /><CustomButtontheme="light"text="mint"//{t('callToAction.mint')}@@ -113,6 +122,9 @@ function Save() {onClick={mint}/></div>+ {showOnChainPublish && (+ <OnChainPublish onClose={() => setShowOnChainPublish(false)} />+ )}<MessageWindowcancelOption = {false}confirmDialogText = {dialogMessage}diff --git a/chat/src/Input.svelte b/chat/src/Input.svelteindex 5e93426d8..ff573df3a 100644--- a/chat/src/Input.svelte+++ b/chat/src/Input.svelte@@ -521,7 +521,7 @@ ${file.contents}>{#if $mode === 'website'}<button- class="three.ws-chip three.ws-chip-selected h-7 px-3 text-xs"+ class="three-ui-chip three-ui-chip-selected h-7 px-3 text-xs"on:click={() => mode.set(null)}>Website@@ -529,7 +529,7 @@ ${file.contents}{/if}{#if $mode === 'desktop'}<button- class="three.ws-chip three.ws-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"+ class="three-ui-chip three-ui-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"on:click={() => mode.set(null)}><Icon icon={feSmartphone} class="w-3.5 h-3.5" />@@ -537,7 +537,7 @@ ${file.contents}</button><div class="relative"><button- class="three.ws-chip h-7 px-3 text-xs inline-flex items-center gap-1.5"+ class="three-ui-chip h-7 px-3 text-xs inline-flex items-center gap-1.5"on:click={() => { platformsOpen = !platformsOpen; }}>{platformsSummary}@@ -572,7 +572,7 @@ ${file.contents}{/if}{#if $mode === 'slides'}<button- class="three.ws-chip three.ws-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"+ class="three-ui-chip three-ui-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"on:click={() => mode.set(null)}><Icon icon={feLayout} class="w-3.5 h-3.5" />@@ -580,7 +580,7 @@ ${file.contents}</button><div class="relative"><button- class="three.ws-chip h-7 px-3 text-xs inline-flex items-center gap-1.5"+ class="three-ui-chip h-7 px-3 text-xs inline-flex items-center gap-1.5"on:click={() => { toneOpen = !toneOpen; imgModelOpen = false; }}><Icon icon={feZap} class="w-3.5 h-3.5" />@@ -625,7 +625,7 @@ ${file.contents}{/if}{#if $mode === 'design'}<button- class="three.ws-chip three.ws-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"+ class="three-ui-chip three-ui-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5"on:click={() => mode.set(null)}><Icon icon={feZap} class="w-3.5 h-3.5" />@@ -648,7 +648,7 @@ ${file.contents}{#if $mode && modeConfig[$mode]}{@const cfg = modeConfig[$mode]}<button- class="three.ws-chip three.ws-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5 shrink-0"+ class="three-ui-chip three-ui-chip-selected h-7 px-3 text-xs inline-flex items-center gap-1.5 shrink-0"on:click={() => mode.set(null)}><Icon icon={cfg.icon} class="w-3.5 h-3.5" />@@ -659,7 +659,7 @@ ${file.contents}{@const currentVal = $flowSecondary[$mode] ?? sec.default}<div class="relative"><button- class="three.ws-chip h-7 px-3 text-xs inline-flex items-center gap-1.5 shrink-0"+ class="three-ui-chip h-7 px-3 text-xs inline-flex items-center gap-1.5 shrink-0"on:click={() => { secondaryOpen = secondaryOpen === $mode ? null : $mode; }}>{sec.prefix}: {currentVal}diff --git a/chat/src/three-ui/flows/DesktopFlow.svelte b/chat/src/three-ui/flows/DesktopFlow.svelteindex e168f3dba..ecc5a1d2c 100644--- a/chat/src/three-ui/flows/DesktopFlow.svelte+++ b/chat/src/three-ui/flows/DesktopFlow.svelte@@ -82,7 +82,7 @@<div class="flex flex-wrap gap-2">{#each platforms as p}<button- class="three.ws-chip {$appPlatforms.has(p.id) ? 'three.ws-chip-selected' : ''}"+ class="three-ui-chip {$appPlatforms.has(p.id) ? 'three-ui-chip-selected' : ''}"on:click={() => togglePlatform(p.id)}><Icon icon={p.icon} size={16} />@@ -95,7 +95,7 @@<h3 class="text-sm font-semibold mt-10 mb-3">Explore ideas</h3><div class="flex flex-wrap gap-2">{#each ideas as idea}- <button class="three.ws-chip" on:click={() => selectIdea(idea)}>+ <button class="three-ui-chip" on:click={() => selectIdea(idea)}>{idea}<Icon icon={feArrowUpLeft} size={14} class="text-[#9C9A93]" /></button>diff --git a/chat/src/three-ui/flows/WebsiteFlow.svelte b/chat/src/three-ui/flows/WebsiteFlow.svelteindex d1771ca1e..d5fa0b0d9 100644--- a/chat/src/three-ui/flows/WebsiteFlow.svelte+++ b/chat/src/three-ui/flows/WebsiteFlow.svelte@@ -73,7 +73,7 @@<div class="mt-4 flex gap-2 overflow-x-auto scrollbar-none">{#each categories as c}<button- class="three.ws-chip whitespace-nowrap {$websiteCategory === c.id ? 'three.ws-chip-selected' : ''}"+ class="three-ui-chip whitespace-nowrap {$websiteCategory === c.id ? 'three-ui-chip-selected' : ''}"on:click={() => pick(c.id)}><Icon icon={c.icon} size={16} />@@ -87,7 +87,7 @@<h3 class="text-sm font-semibold mb-3">Explore ideas</h3><div class="flex flex-wrap gap-2">{#each ideasByCategory[$websiteCategory] as idea}- <button class="three.ws-chip" on:click={() => selectIdea(idea)}>+ <button class="three-ui-chip" on:click={() => selectIdea(idea)}><span>{idea}</span><Icon icon={feArrowUpLeft} size={14} class="text-[#9C9A93]" /></button>