Guide for Vibe Coders

Vibe Coding with Bitcoin Agents

Build AI agents with their own Bitcoin wallets and payment-gated APIs. No coding experience required.

What you'll build
🤖

Claude Code

An AI coding assistant that writes and runs code for you in your terminal.

💳

Agent Wallet

Your AI gets its own Stacks wallet to send transactions and interact with DeFi.

x402 Endpoint

A payment-gated API that accepts STX, sBTC, or USDCx for access.

The Guide

Follow the steps below. Click each section to expand.

1

Setting Up Claude Code

~5 min

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.

Install Prerequisites

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

Install Claude Code

npm install -g @anthropic-ai/claude-code

Run Claude Code

claude

The first time you run it, Claude Code will ask you to log in with your Anthropic account. Follow the prompts.

💡
Once you're in, try asking: "What can you help me build?"

Your AI agent needs its own wallet to send and receive payments. We'll use the Stacks MCP Server to give Claude wallet capabilities.

What's an MCP Server?

MCP (Model Context Protocol) lets you give Claude new abilities. The Stacks MCP Server enables:

  • Creating and managing Stacks wallets
  • Checking balances and sending tokens
  • Interacting with DeFi protocols
  • Executing smart contracts

Clone the Stacks MCP Server

# 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
📦
Don't have pnpm? Install it first with: npm install -g pnpm
⚠️
Important: Use a fresh wallet for your agent, never your personal wallet.

Create Your Agent's Wallet

# Generate a new Stacks wallet
npx @stacks/cli make_keychain -t

Configure the Environment

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.

Connect to Claude Code

# Run the setup script
pnpm setup

# Or manually add it
claude mcp add stacks-mcp -- node /path/to/stacks-mcp-server/dist/index.js

Test Your Wallet

Restart Claude Code and try asking:

  • "What's my STX balance?"
  • "Send 1 STX to ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM"

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 AIBTC x402 Stack

  • x402.aibtc.dev (testnet) — The API host
  • x402-sponsor-relay — Gasless transactions for agents
  • Supported tokens: STX, sBTC, USDCx

Option A: Use Existing x402 API

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."

Option B: Deploy Your Own Endpoint

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

Option C: Gasless Transactions

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:

  1. Your agent has a wallet with testnet STX
  2. Someone calls your x402 endpoint and gets a 402 response
  3. They pay in STX, sBTC, or USDCx
  4. Your endpoint verifies and returns the content
  5. Payment goes to your agent's wallet

Example: AI Advice Agent

Ask Claude:

🚀
"Help me create an x402 endpoint that charges 0.01 STX for AI-generated advice. Deploy it on Cloudflare Workers."

Claude will help you set up routes, connect to an LLM, handle payments, and deploy.

Quick Reference

Everything you need in one place.

Common Questions

Do I need to know how to code?
Not really. Claude Code writes the code for you. Just describe what you want in plain English.
Is this safe to use with real money?
Start on testnet. Only move to mainnet once you understand what's happening. Always use a dedicated agent wallet, never your personal funds.
What can I build with this?
  • Pay-per-query AI endpoints
  • Premium content APIs
  • Agent-to-agent payment flows
  • Automated trading bots
  • DAO participation tools
What if something breaks?
Ask Claude. Paste the error message and ask it to help you debug. That's the vibe coder way.

Ready to build?

Start with Step 1 and work your way through. You've got this.

Start the Guide