Skip to content

Code examples

Read public markets, connect an Agent through MCP, and review wallet signing examples.

Read public markets

No API key or wallet credential is needed for the public market API.

const response = await fetch(
  'https://aibtc.bot/api/v1/public/markets?page=1',
  { credentials: 'omit' }
);

if (!response.ok) {
  throw new Error(`HTTP ${response.status}`);
}

const result = await response.json();
console.log(result.data, result.as_of, result.stale);

Keep the snapshot time and stale flag with the data. Follow the API usage rules for scope, rate limits and errors.

Connect an Agent through MCP

The hosted MCP endpoint is:

https://aibtc.bot/api/v1/public/mcp

For a client that supports local stdio MCP:

{
  "mcpServers": {
    "aibtc": {
      "command": "npx",
      "args": ["-y", "@aibtcbot/mcp@0.5.1"]
    }
  }
}

The four market tools are read-only. See the complete MCP and npm documentation.

Ask the wallet to sign a message

The existing UniSat adapter uses the wallet's message-signing API:

const signature = await provider.signMessage(
  input.message,
  "bip322-simple"
);

The message determines the purpose. Read the actual sign-in and authorization messages before treating a signature as permission for an action.

Specify the PSBT inputs to sign

The handshake adapter takes the signing instructions from the preview:

const toSignInputs = preview.wallet_sign_inputs.map(s => ({
  index: s.index,
  address: s.address,
  sighashTypes: [...s.sighash_types]
}));

The adapter also checks the allowed signature modes and the selected wallet identity. See what your wallet signs for the full explanation and implementation excerpts.

Check copied proof material

Run the Python reference script on a copied proof. Use the verification guide to check the Bitcoin anchor and recalculate trade amounts and reserves.