Build AI agents with their own Bitcoin wallets and payment-gated APIs. No coding experience required.
An AI coding assistant that writes and runs code for you in your terminal.
Your AI gets its own Stacks wallet to send transactions and interact with DeFi.
A payment-gated API that accepts STX, sBTC, or USDCx for access.
Follow the steps below. Click each section to expand.
Claude Code is a command-line AI assistant that can read, write, and run code. Think of it as having a developer working alongside you in your terminal.
You'll need Node.js installed. Open your terminal and run:
# Check if you have Node.js
node --version
# If you don't have it, install via Homebrew (Mac)
brew install node
# Or download from https://nodejs.org
npm install -g @anthropic-ai/claude-code
claude
The first time you run it, Claude Code will ask you to log in with your Anthropic account. Follow the prompts.
Your AI agent needs its own wallet to send and receive payments. We'll use the Stacks MCP Server to give Claude wallet capabilities.
MCP (Model Context Protocol) lets you give Claude new abilities. The Stacks MCP Server enables:
# Create a directory for your project
mkdir bitcoin-agent && cd bitcoin-agent
# Clone the MCP server
git clone https://github.com/Stack-AI-MCP/stacks-mcp-server.git
cd stacks-mcp-server
# Install dependencies
pnpm install
# Build the server
pnpm build
npm install -g pnpm# Generate a new Stacks wallet
npx @stacks/cli make_keychain -t
cp .env.example .env
Edit .env with your wallet details:
WALLET_PRIVATE_KEY=your_private_key_here
STACKS_NETWORK=testnet
STACKS_TESTNET_API_URL=https://api.testnet.hiro.so
Get free test STX from the Stacks faucet.
# Run the setup script
pnpm setup
# Or manually add it
claude mcp add stacks-mcp -- node /path/to/stacks-mcp-server/dist/index.js
Restart Claude Code and try asking:
x402 lets you charge for API access using crypto. When someone hits your endpoint without paying, they get a 402 "Payment Required" response. Once they pay, they get the content.
The easiest path — consume AIBTC's existing endpoints:
# This returns 402 with payment requirements
curl https://x402.aibtc.dev/inference/chat
Ask Claude: "Help me write a script that calls x402.aibtc.dev and handles the payment flow."
Create your own payment-gated API:
# Clone the x402-api template
git clone https://github.com/aibtcdev/x402-api.git
cd x402-api
npm install
Ask Claude: "Help me add an endpoint that charges 0.001 STX to return a joke."
# Deploy to Cloudflare
npx wrangler login
npx wrangler deploy --env staging
Use the sponsor relay so your agent doesn't need STX for gas:
POST https://x402-relay.aibtc.dev/relay
Now you have all the pieces. Here's the complete flow:
Ask Claude:
Claude will help you set up routes, connect to an LLM, handle payments, and deploy.
Everything you need in one place.