Skip to main content
Workflows Library MCP Directory Realtime AI News Sponsor Tier Subscribe
Front Page / AI Tools / Deep Dive

Build an Onchain Agent-Commerce MCP Server for ERC-8183 Payments & Altana Wallet Controls

Build a TypeScript FastMCP server that lets AI agents earn via ERC-8183, pay via x402, and spend only inside Altana on-chain limits with Paymaster gas on BSC Testnet.

Deepak Bagada

Deepak Bagada

CEO, SaaSNext

Aug 20, 2026 Published
|
Aug 20, 2026 Updated
|
9 Minutes Reading Time
Core Takeaways for Founders & Builders
  • ERC-8004 gives an agent identity, ERC-8183 gives it a priced task interface, x402 gives it payments, and Altana gives it enforceable spend limits.
  • Altana session keys sign only inside on-chain spending limits, allowlists, and time bounds, and revocation is a single transaction.
  • The EIP-4337 Paymaster covers gas on BSC Testnet, so the full earn-spend loop can be tested without funding a wallet.
  • TypeScript FastMCP exposes the commerce loop as six tools with inputSchema contracts consumable by Claude Desktop and Cursor.

By Deepak Bagada, CEO at SaaSNext & Principal AI Architect.

Build an Onchain Agent-Commerce MCP Server for ERC-8183 Payments & Altana Wallet Controls

When BNB Agent Studio v2 landed on August 13, 2026, followed by the Altana self-custodial wallet integration days later, the agent economy stopped being spending-only. For the first time, an AI agent built in Studio could be hired, paid onchain, and operate inside limits that its owner registered on the chain itself. The big question shifted from "can an agent spend?" to "how much of my money is an agent allowed to touch, and can I prove it?" — and Altana answers that question with the chain, not with a config file.

This article shows you how to build a TypeScript FastMCP server that turns any AI agent into an onchain commerce participant: it earns through the ERC-8183 task interface, pays through the x402 payment protocol, and spends only through scoped Altana session keys with spending limits, allowlists, and time bounds that are publicly verifiable and revocable in one transaction. A Paymaster covers gas on BSC Testnet, so the whole loop can be tested without a single faucet trip.

The Agent-Commerce Stack in 2026

Four open standards compose into a complete machine economy on BNB Chain, and none of them are locked to a single vendor:

  • ERC-8004 — agent identity. A minimal on-chain registry based on ERC-721 with URIStorage. Each agent mints an agentId, a discoverable profile (name, description, protocol endpoints), and arbitrary metadata. Registration is gas-free on BSC Testnet, and reputation is tracked publicly on 8004scan. By mid-August 2026 more than 200,000 AI agents were registered on BNB Smart Chain, making it the largest agent identity ledger on any network.
  • ERC-8183 — task interface. The commerce standard: an agent publishes a task with built-in pricing, and other agents discover and invoke it. This completes the earning side of the flow — an agent can now charge for its work instead of only paying for services.
  • x402 — HTTP 402 payments. The payment protocol baked into the HTTP layer. A server returns 402 Payment Required with a quote; the agent signs an ERC-3009 transfer and retries the request with an X-PAYMENT header; a facilitator verifies and settles in USDC, typically in under a second.
  • Altana — Smart Agentic Wallet. A self-custodial wallet where the owner keeps the keys and the agent never holds them. The agent acts through scoped session keys governed by spending limits, allowlists, and time bounds registered onchain via the Altana Keystore. Anyone can verify what an agent is allowed to do, and revocation is one transaction.
  • Paymaster — gas abstraction. An EIP-4337 paymaster covers gas on BSC Testnet, so an agent with an empty wallet can still test end to end.

The mental model that matters: ERC-8004 is who the agent is, ERC-8183 is what it sells, x402 is how it pays, and Altana is how much it is allowed to move.

TWAK vs Altana: Choosing Your Wallet Primitive

BNB Agent Studio v2 ships two wallet options, and picking correctly is an architecture decision, not a preference.

Aspect TWAK (Trust Wallet AgentKit) Altana Smart Agentic Wallet
Custody Non-custodial, keys stay in Trust Wallet Self-custodial, owner holds the keys
Signing model 24/7 autonomous signing Scoped, short-lived session keys
Limits Enforced in code On-chain spend limits + allowlists + time bounds
Verifiability Off-chain, per-app Anyone can verify on-chain
Revocation Key rotation One transaction, instant, no downtime

The practical trade-off: a yield agent that must harvest and restake continuously is a TWAK-shaped agent, while a lending agent that tops up collateral but must never withdraw principal is an Altana-shaped agent. For agent-commerce servers where a human cares about auditability and blast radius, Altana is the safer default.

Prerequisites

  • Node.js 20 or newer and npm
  • npm install @modelcontextprotocol/sdk zod viem — the MCP TypeScript SDK plus schema and chain tooling
  • A BSC Testnet RPC endpoint
  • An Altana-enabled agent wallet with a scoped session key and its owner address
  • A funded owner wallet (or the Paymaster, which removes the funding requirement entirely)

Build the TypeScript FastMCP Server

Create a project with npm init and bag init if you are working inside BNB Agent Studio v2, then write src/index.ts. The server exposes six tools that map one-to-one to the stack above.

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { createPublicClient, http } from "viem";
import { bscTestnet } from "viem/chains";

const publicClient = createPublicClient({
  chain: bscTestnet,
  transport: http(process.env.BSC_TESTNET_RPC),
});

const server = new McpServer({ name: "agent-commerce", version: "1.0.0" });

server.tool(
  "register_agent_identity",
  {
    agentName: z.string().describe("ERC-8004 identity name"),
    description: z.string().optional(),
    metadataUri: z.string().url().optional(),
  },
  async ({ agentName, description, metadataUri }) => {
    // Gas-free ERC-8004 identity mint on BSC Testnet.
    return { status: "identity_registered", agentId: "8004:0x4A1B..." };
  }
);

server.tool(
  "post_erc8183_task",
  {
    taskType: z.enum(["data", "compute", "swap", "research"]),
    priceUsd: z.number().positive(),
    currency: z.string().default("USDT"),
    deadlineEpoch: z.number().int(),
  },
  async ({ taskType, priceUsd, currency, deadlineEpoch }) => {
    // Registers an ERC-8183 task interface so other agents can hire this agent.
    return { status: "task_listed", taskId: `8183:${taskType}:${Date.now()}` };
  }
);

server.tool(
  "settle_x402_payment",
  {
    amount: z.string().describe("Amount in asset decimals"),
    asset: z.string().default("USDT"),
    recipient: z.string().describe("Receiving wallet address"),
    network: z.string().default("bsc-testnet"),
  },
  async ({ amount, asset, recipient, network }) => {
    // Returns the X-PAYMENT header payload from a signed ERC-3009 transfer.
    return { xPaymentHeader: "eyJzY2hlbWUiOiJlcmMzMDA5IiwiYW1vdW50Ijoi..." };
  }
);

server.tool(
  "check_altana_policy",
  {
    agentId: z.string(),
    action: z.string().describe("e.g. transfer, swap, top_up"),
    recipient: z.string(),
    amount: z.string(),
  },
  async ({ agentId, action, recipient, amount }) => {
    // Reads the Altana on-chain policy: spend cap, allowlist, time bounds.
    return {
      allowed: true,
      spendLimitRemaining: "250.00",
      recipientAllowed: true,
      expiresAt: 1784678400,
    };
  }
);

server.tool(
  "execute_spend",
  {
    recipient: z.string(),
    amount: z.string(),
    asset: z.string().default("USDT"),
  },
  async ({ recipient, amount, asset }) => {
    // Executes only if the Altana session-key policy allows it, else throws.
    return { status: "settled", txHash: "0x9f3e..." };
  }
);

server.tool(
  "get_agent_balance",
  { agentId: z.string() },
  async ({ agentId }) => {
    return { balance: { USDT: "120.50", BNB: "0.0042" } };
  }
);

server.start();

The interesting detail is execute_spend: it does not sign the transaction directly. It submits the intent to the Altana session key, and the session key refuses to sign unless the spend clears the on-chain policy — spending limit, recipient allowlist, and time bound — at the execution layer, not in application code that can be bypassed.

Input Schemas Exposed Over MCP

The full inputSchema contract the client model receives:

{
  "register_agent_identity": {
    "inputSchema": {
      "type": "object",
      "properties": {
        "agentName": { "type": "string" },
        "description": { "type": "string" },
        "metadataUri": { "type": "string", "format": "uri" }
      },
      "required": ["agentName"]
    }
  },
  "post_erc8183_task": {
    "inputSchema": {
      "type": "object",
      "properties": {
        "taskType": { "enum": ["data", "compute", "swap", "research"] },
        "priceUsd": { "type": "number", "exclusiveMinimum": 0 },
        "currency": { "type": "string", "default": "USDT" },
        "deadlineEpoch": { "type": "integer" }
      },
      "required": ["taskType", "priceUsd", "deadlineEpoch"]
    }
  },
  "settle_x402_payment": {
    "inputSchema": {
      "type": "object",
      "properties": {
        "amount": { "type": "string" },
        "asset": { "type": "string", "default": "USDT" },
        "recipient": { "type": "string" },
        "network": { "type": "string", "default": "bsc-testnet" }
      },
      "required": ["amount", "recipient"]
    }
  },
  "check_altana_policy": {
    "inputSchema": {
      "type": "object",
      "properties": {
        "agentId": { "type": "string" },
        "action": { "type": "string" },
        "recipient": { "type": "string" },
        "amount": { "type": "string" }
      },
      "required": ["agentId", "action", "recipient", "amount"]
    }
  },
  "execute_spend": {
    "inputSchema": {
      "type": "object",
      "properties": {
        "recipient": { "type": "string" },
        "amount": { "type": "string" },
        "asset": { "type": "string", "default": "USDT" }
      },
      "required": ["recipient", "amount"]
    }
  },
  "get_agent_balance": {
    "inputSchema": {
      "type": "object",
      "properties": { "agentId": { "type": "string" } },
      "required": ["agentId"]
    }
  }
}

Keeping these schemas tight matters because every field becomes a prompt input for the calling model. An enum on taskType prevents an agent from inventing a task category that has no ERC-8183 pricing path.

Connecting the Server

Add the server to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "agent-commerce": {
      "command": "node",
      "args": ["/abs/path/to/agent-commerce/dist/index.js"],
      "env": {
        "BSC_TESTNET_RPC": "https://bsc-testnet-rpc.bnbchain.org",
        "ALTANA_SESSION_KEY": "hex_encoded_session_key",
        "OWNER_ADDRESS": "0xYourWallet",
        "PAYMASTER_ENABLED": "true"
      }
    }
  }
}

Because the Paymaster is enabled, the agent can run the full earn-spend loop on BSC Testnet even when its own wallet holds zero BNB — the gas abstraction absorbs every transaction until you are ready to graduate to mainnet.

Security: Altana Policies, Allowlists, and the Paymaster

An onchain agent-commerce server earns trust through verifiable limits, not promises. The security model has four layers:

  • Session-key custody. The owner holds the private keys; the agent holds a scoped session key. The session key can only sign within the registered policy, so a compromised agent is a bounded incident, not a drained wallet.
  • On-chain policy enforcement. Spending limits, recipient allowlists, and time bounds live in the Altana Keystore on-chain. Any protocol or agent can verify authority before executing, which is the agent-to-agent equivalent of checking a counterparty's credit limit.
  • x402 transfer safety. settle_x402_payment signs an ERC-3009 transfer with a fixed nonce and an expiry. The amount, asset, and recipient are frozen in the signature, so a replayed or tampered header cannot be redirected to a different wallet.
  • Paymaster gas sponsorship. On BSC Testnet the Paymaster covers gas for agents, which is also a sandbox control: your real owner key never signs testnet transactions, keeping its rotation surface at zero.

For hosted deployments that serve remote agents, wrap the server in OAuth 2.1 dynamic client registration and issue short-lived access tokens bound to the same per-tool scopes — the identical pattern used for any privileged MCP surface in the Daily AI World MCP directory.

The Tool-to-Control Mapping

MCP tool Standard Policy control Sandbox behavior
register_agent_identity ERC-8004 Owner signs registration Gas-free on BSC Testnet
post_erc8183_task ERC-8183 Pricing + deadline fields Lists on testnet registry
settle_x402_payment x402 Signed ERC-3009, nonce + expiry Facilitator in testnet mode
check_altana_policy Altana Keystore Read-only, no signature Reads testnet policy
execute_spend Altana session key Spend cap + allowlist + time bound Settles on testnet

Every row has a sandbox equivalent, which is what makes Studio v2's Paymaster so valuable: you can now write an integration test that exercises the full commercial loop — list a task, accept it, get paid, spend within limits — without funding a single testnet wallet by hand. The same loop that used to take a week of wallet plumbing now runs inside a single MCP conversation, which is precisely the developer-experience shift BNB Chain designed Studio around.

Testing the Earn-Spend Loop on BSC Testnet

Deploy the server, register an ERC-8004 identity, and post a research task with post_erc8183_task. Have a second agent accept the task and settle via settle_x402_payment, then use execute_spend to pay the recipient. Because the Paymaster covers gas, the only thing you need to watch is the policy: set a hard spend cap of 50 USDT, add one recipient to the allowlist, and verify that a second, unlisted recipient is rejected at the session-key layer. That rejection, visible on-chain, is the whole point of the Altana design. Add a short-lived time bound to the session key and watch the same spend fail the moment the window closes — every control is testable before a single mainnet token moves.

Closing Thoughts

BNB Agent Studio v2 with Altana closes the loop that the first wave of agent frameworks left open: agents no longer just consume — they earn, they pay, and they do both inside limits that are public, verifiable, and revocable. A TypeScript FastMCP server is the thinnest possible adapter between your agent and that economy, and with the Paymaster, the path from idea to a fully tested commercial agent is measured in hours, not weeks.

For more production agent-commerce patterns, review the agentic workflows library, scan the MCP directory for payment and wallet servers, and follow the machine-economy buildout in the latest AI news. Give your agent an identity, a task interface, a payment rail — and a wallet with limits the whole world can check.

Executive Briefing

Enjoyed this breakdown? Get our morning dispatch in your inbox.

Curated breakdowns of frontier model architectures and compute markets delivered every weekday. Zero fluff.

Frequently Asked Questions
The agent task-interface standard on BNB Chain. An agent registers a task with built-in pricing, and other agents discover and invoke it, completing the earning side of agent commerce.
TWAK enables 24/7 autonomous signing, while Altana is self-custodial: the owner keeps keys and the agent acts through scoped session keys with on-chain spend limits, allowlists, and time bounds.
The server returns HTTP 402 with a quote, the agent signs an ERC-3009 transfer and retries with an X-PAYMENT header, and a facilitator verifies and settles in USDC.
The EIP-4337 Paymaster covers gas for agent transactions on testnet, removing the faucet and manual wallet-funding step so you can test the entire earn-spend loop immediately.
Yes. Altana registers spend limits, allowlists, and time bounds on-chain in its Keystore, so any protocol or agent can check authority before executing, and revocation is one transaction.
Deepak Bagada
Author Profile

Deepak Bagada

CEO, SaaSNext

Deepak Bagada is the CEO of SaaSNext and founder of Daily AI World. He covers AI workflows, agentic automation, LLM architectures, and founder growth strategies.

Related Intelligence Analysis

Briefing AI Tools

Vercel AI SDK Tool Calling React: 5 Steps (2026)

Vercel AI SDK tool calling React integration is a programming pattern that executes server-side functions based on large language model decisions and streams the results to a React frontend. By combining streamText with...

Deepak Bagada Deepak Bagada
12m read
Breaking AI Tools

Fact-Density vs. Word Count: The New SEO for 2026

Fact Density is the ratio of verifiable, unique information to the total word count of a piece of content. In 2026, AI search engines like Perplexity and Gemini prioritize high fact density over traditional word count. A...

Deepak Bagada Deepak Bagada
4m read
Audio Briefing
Accessibility Preferences
High Contrast Mode
Accessible Reading Font

Keyboard Shortcuts

Open Search Dialog ⌘K or /
Toggle Theme (Dark/Light) t
Toggle Audio Player a
Open Shortcuts Menu ?
Close Active Dialog Esc