Spaces:
Running
Running
| // One-time script: register RenderGate as an 8004 agent on Stellar testnet. | |
| // Re-run safely β if metadata changes, use updateAgentUri() instead (see bottom). | |
| // | |
| // Usage: node scripts/register-8004.js | |
| // Requires: AGENT_OWNER_SECRET_TESTNET in .env | |
| import "dotenv/config"; | |
| import { Keypair } from "@stellar/stellar-sdk"; | |
| import { | |
| createClients, | |
| TESTNET_CONFIG, | |
| wrapBasicSigner, | |
| buildMetadataJson, | |
| toDataUri, | |
| validateMetadataJson, | |
| ExplorerClient, | |
| } from "@trionlabs/stellar8004"; | |
| const SECRET = process.env.AGENT_OWNER_SECRET_TESTNET; | |
| if (!SECRET) { | |
| console.error("ERROR: AGENT_OWNER_SECRET_TESTNET not set in .env"); | |
| process.exit(1); | |
| } | |
| // 1. Build metadata | |
| const metadata = buildMetadataJson({ | |
| name: "RenderGate", | |
| description: | |
| "Pay-per-render headless browser API for AI agents. Renders JS-heavy pages (Twitter, LinkedIn, SPAs) and returns structured content. Auto-refunds when pages are blocked.", | |
| imageUrl: "https://tantk.github.io/rendergate-githubpage/logo.png", | |
| services: [ | |
| { | |
| name: "x402", | |
| endpoint: "https://tantk-rendergate.hf.space/render", | |
| version: "1.0", | |
| description: | |
| "Render a JS-heavy webpage and return title, description, headings, links, and full text content. $0.001 USDC per render.", | |
| inputExample: '{"url": "https://x.com/stellarorg"}', | |
| }, | |
| { | |
| name: "mcp", | |
| endpoint: "https://tantk-rendergate.hf.space/render", | |
| }, | |
| ], | |
| supportedTrust: ["reputation"], | |
| x402Enabled: true, | |
| }); | |
| console.log("Metadata to register:"); | |
| console.log(JSON.stringify(metadata, null, 2)); | |
| console.log(); | |
| validateMetadataJson(metadata); | |
| const dataUri = toDataUri(metadata); | |
| console.log(`Data URI size: ${dataUri.length} bytes (limit 8KB)\n`); | |
| // 2. Set up signer + clients | |
| const keypair = Keypair.fromSecret(SECRET); | |
| const signer = wrapBasicSigner(keypair, TESTNET_CONFIG.networkPassphrase); | |
| const { identity } = createClients(TESTNET_CONFIG, signer); | |
| console.log(`Owner address: ${keypair.publicKey()}`); | |
| console.log("Submitting register_with_uri to testnet Identity Registry...\n"); | |
| // 3. Register on-chain | |
| const tx = await identity.register_with_uri({ | |
| caller: keypair.publicKey(), | |
| agent_uri: dataUri, | |
| }); | |
| const sent = await tx.signAndSend(); | |
| const agentId = sent.result; | |
| console.log(`β Registered! Agent ID: ${agentId}`); | |
| console.log(` Tx hash: ${sent.getTransactionResponse?.hash || "(see logs)"}`); | |
| console.log(); | |
| console.log("Save this ID β it's your agent's permanent identifier:"); | |
| console.log(` AGENT_ID=${agentId}`); | |
| console.log(); | |
| console.log( | |
| `Explorer page (allow ~30-60s for indexing): https://stellar8004.com/agents/${agentId}`, | |
| ); | |
| // 4. Optional: verify via explorer once indexed | |
| const explorer = new ExplorerClient(); | |
| console.log("\nWaiting 5s, then querying explorer..."); | |
| await new Promise((r) => setTimeout(r, 5000)); | |
| try { | |
| const agent = await explorer.getAgent(agentId); | |
| console.log("Explorer record:", agent ? "found" : "not yet indexed"); | |
| } catch (err) { | |
| console.log("Explorer query:", err.message); | |
| } | |