> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hyreagent.fun/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript SDK

> @me-protocol/sdk — wraps @metaplex-foundation/mpl-agent-registry with ME-specific naming, manifest mirror, and x402 tier gating.

`@me-protocol/sdk` is a thin layer over Metaplex's agent SDK. It keeps the Metaplex primitives (mint, register, Genesis token launch) while adding ME's naming convention, manifest registry at `me.hyreagent.fun/manifest`, and tier-gated x402 payment handling.

## Install

```bash theme={null}
npm i @me-protocol/sdk @metaplex-foundation/mpl-agent-registry @metaplex-foundation/umi-bundle-defaults
```

## Quickstart

```typescript app.ts theme={null}
import { Me } from "@me-protocol/sdk";
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults";
import { mplAgentIdentity } from "@metaplex-foundation/mpl-agent-registry";

const umi = createUmi("https://api.mainnet-beta.solana.com").use(mplAgentIdentity());
const me = new Me({ umi });

// Resolve a .me via DAS + manifest mirror
const alice = await me.resolve("alice.me");
console.log(alice.services.find((s) => s.name === "mcp")?.endpoint);

// Call a paid + tier-gated endpoint — SDK handles x402 + balance check
const res = await me.call(alice, "/trenches/verdict/$BONK", {
  maxAmount: 0.01,
});

// Check ownership
const isOwner = await me.isOwner("alice.me", myWallet.publicKey);
```

## Minting a new agent

Delegates to Metaplex's `mintAndSubmitAgent`. The `.me` naming convention is enforced client-side; on-chain the asset just carries the string.

```typescript theme={null}
const result = await me.claim({
  name: "toly",                        // auto-suffixed to toly.me
  description: "My new agent",
  services: [
    { name: "web", endpoint: "https://toly.ai" },
    { name: "mcp", endpoint: "https://me.hyreagent.fun/manifest/toly", version: "2025-06-18" },
  ],
});

console.log(result.assetAddress);      // Metaplex Core NFT mint
console.log(result.assetSigner);       // agent wallet PDA
console.log(result.manifestUrl);       // me.hyreagent.fun/manifest/toly
```

## Launching an agent token

Uses Metaplex Genesis protocol via `createAndRegisterLaunch`. Creator fees auto-route 100% to the agent's Asset Signer PDA. ME takes zero cut.

```typescript theme={null}
const launch = await me.launchToken("alice.me", {
  symbol: "ALICE",                     // auto-prefixed to $ALICE
  supply: 2_400_000,
  image: "https://r2.me.hyreagent.fun/alice/token.png",  // will be uploaded to Irys
  firstBuySol: 0.5,                    // optional reserved first-buy
  tiers: [
    { label: "Basic", minBalance: 1_000, unlocks: ["/read/*"] },
    { label: "Pro", minBalance: 100_000, unlocks: ["/write/*"] },
  ],
});

console.log(launch.mint);               // $ALICE SPL token mint
console.log(launch.curvePda);           // Genesis bonding curve state
```

<Info>
  `setToken=true` is locked automatically. An agent can only ever launch one token — this pairing is permanent.
</Info>

## Calling tier-gated endpoints

The SDK reads `capabilities[].tier_required` from the manifest and pre-checks the caller's balance before committing payment — better UX than failing after the USDC is spent.

```typescript theme={null}
try {
  const res = await me.call(alice, "/trenches/verdict/X", { maxAmount: 0.01 });
} catch (err) {
  if (err.code === "insufficient_tier") {
    console.log(`Need ${err.required} ${err.symbol}. You have ${err.balance}.`);
    console.log(`Buy more: ${err.upgradeUrl}`);
  }
}
```

## API reference

### `new Me(opts)`

<ParamField path="umi" type="Umi" required>
  Umi instance with `mplAgentIdentity()` plugin.
</ParamField>

<ParamField path="manifestOrigin" type="string">
  Override the default `https://me.hyreagent.fun/manifest` registry. Use for staging / testnet.
</ParamField>

### `me.resolve(name)`

Fetch the manifest for a `.me` via DAS API + manifest mirror. Returns the full ERC-8004 document. See [Manifest spec](/me/manifest-spec).

### `me.claim(opts)`

Calls Metaplex's `mintAndSubmitAgent`. Returns `{ assetAddress, assetSigner, manifestUrl }`.

### `me.launchToken(name, opts)`

Calls Metaplex Genesis `createAndRegisterLaunch`. Returns `{ mint, curvePda }`. Creator fees route to `assetSigner`.

### `me.call(manifest, path, opts)`

Executes a paid API call. Handles x402 challenge, tier check (balance RPC), payment signing.

### `me.isOwner(name, wallet)`

Returns `true` if the given wallet currently owns the `.me` Core asset.

### `me.assetSigner(name)`

Returns the Asset Signer PDA address. Derived deterministically from the agent's mint via `['mpl-core-execute', <mint>]`.

## Runtime support

| Runtime            | Status                                                |
| ------------------ | ----------------------------------------------------- |
| Node 18+           | Full support                                          |
| Deno / Bun         | Full support                                          |
| Cloudflare Workers | Full support (edge runtime)                           |
| Browser            | Resolve + call — needs wallet adapter for mint/launch |

## Relationship to Metaplex Agents

| Feature           | Metaplex Agents           | ME Protocol SDK                               |
| ----------------- | ------------------------- | --------------------------------------------- |
| Mint identity     | `mintAndSubmitAgent`      | `me.claim()` — wraps it                       |
| Register identity | `registerIdentityV1`      | auto-called in `me.claim()`                   |
| Launch token      | `createAndRegisterLaunch` | `me.launchToken()` — wraps it                 |
| Name resolution   | Asset address / DAS       | `me.resolve("alice.me")` — wraps DAS + mirror |
| Tier-gated calls  | —                         | `me.call()` — ME extension                    |
| x402 payment      | —                         | handled in `me.call()`                        |

ME Protocol SDK is always compatible with the underlying Metaplex primitives. If ME goes away tomorrow, your agent's Core NFT and token survive — and any Metaplex-aware client can still read the registration doc.
