Complete guide to getting Unlock running locally.
- Node.js 18+ and npm 9+
- Chrome browser (for extension testing)
- Git
- Text editor (VS Code recommended)
git clone https://github.com/unlock/unlock-x402.git
cd unlock-x402Install all workspace dependencies:
npm installThis installs dependencies for:
- Root workspace
- Extension
- Publisher SDK
- Demo server
cd publisher-sdk
npm run build
cd ..This compiles TypeScript to JavaScript in publisher-sdk/dist/.
cd demo-server
cp .env.example .envEdit .env and set your wallet address:
PAY_TO_ADDRESS=0xYourWalletAddressHere
NETWORK=base
PORT=3000Getting a wallet address:
- Install MetaMask or Coinbase Wallet
- Create Base network wallet
- Copy address (starts with 0x)
- Fund with small USDC for testing (optional)
npm run devServer starts at http://localhost:3000
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" (toggle in top-right)
- Click "Load unpacked"
- Select the
extensionfolder from this repo - Extension icon appears in toolbar
- Visit
http://localhost:3000in Chrome - Click "Try Premium Article"
- Extension intercepts 402 response
- Payment modal appears
- Click "Unlock Now"
- Content loads (using starter credits)
- Make changes to extension files
- Go to
chrome://extensions/ - Click refresh icon on Unlock extension
- Test changes in new tab
Hot reload not available in MV3 - manual refresh required.
- Edit files in
publisher-sdk/src/ - Rebuild:
cd publisher-sdk
npm run build- Restart demo server to see changes
Or use watch mode:
npm run devUses ts-node for hot reload:
npm run devChanges to src/server.ts reload automatically.
PAY_TO_ADDRESS # Your wallet address (required)
NETWORK # base | bnb | polygon (default: base)
PORT # Server port (default: 3000)
FACILITATOR_URL # Facilitator endpoint (default: Coinbase)No environment variables - configuration stored in Chrome storage.
Extension:
- ✓ Payment modal displays on 402 response
- ✓ Starter credits deducted correctly
- ✓ Daily cap enforced
- ✓ Receipts saved and displayed
- ✓ Auto-pay respects max transaction setting
- ✓ Refund window shown in modal
- ✓ Success/error toasts appear
- ✓ Popup shows correct balances
Publisher SDK:
- ✓ Routes without payment config pass through
- ✓ Routes with payment return 402 without header
- ✓ Valid payment header allows access
- ✓ Invalid payment header returns 402 error
- ✓ Receipt attached to request object
- ✓ X-PAYMENT-RESPONSE header sent
- ✓ Dynamic pricing works
Not implemented yet.
Planned:
- Jest for unit tests
- Puppeteer for extension E2E
- Supertest for SDK integration tests
Extension won't load:
- Check manifest.json syntax
- Ensure all files exist (background.js, content.js, popup.html)
- Check Chrome console for errors
Payments failing:
- Check browser console (F12)
- Look for network errors
- Verify facilitator endpoint accessible
- Check wallet initialization
Storage errors:
- Clear extension data: chrome://extensions → Unlock → Remove
- Reload extension
- Data resets to defaults
Server won't start:
- Check port 3000 not in use:
lsof -i :3000 - Kill conflicting process:
kill -9 <PID> - Verify dependencies installed
- Check
.envfile exists
402 responses not working:
- Verify middleware configured before routes
- Check route paths match exactly
- Test with curl:
curl -v http://localhost:3000/premium/article-1Should return 402 with JSON body
Payment verification failing:
- Check facilitator URL in config
- Test facilitator connectivity
- Verify transaction hash format
- Check network parameter matches
Facilitator timeout:
- Check internet connection
- Try different facilitator URL
- Check firewall/proxy settings
Transaction not confirming:
- Wait for block confirmation (Base: ~2 seconds)
- Check transaction on block explorer
- Verify network congestion status
- Create production build:
cd extension
npm run pack- Upload
unlock-extension.zipto Chrome Web Store - Complete store listing (screenshots, description)
- Submit for review
Review time: 1-3 days
- Publish to npm:
cd publisher-sdk
npm publish --access public- Update docs with npm install instructions
Deploy to cloud platform:
Vercel:
npm install -g vercel
cd demo-server
vercelRailway:
npm install -g @railway/cli
railway init
railway upSet environment variables in hosting platform UI.
- Enable payment caching for repeated resources
- Set aggressive daily caps for testing
- Use auto-pay for trusted domains
- Enable CDN for static assets
- Cache facilitator verification (10 min TTL)
- Use connection pooling
- Enable gzip compression
- Never commit real wallet private keys
- Use testnet addresses for local testing
- Set low payment amounts during development
- Enable CORS only for localhost
- Use environment variables for secrets
- Enable HTTPS only
- Implement rate limiting
- Monitor for unusual payment patterns
- Set up automated refund policies
- x402 Specification: https://x402.org
- Coinbase Facilitator Docs: https://docs.x402.coinbase.com
- Chrome Extension MV3 Guide: https://developer.chrome.com/docs/extensions/mv3
- Base Network Docs: https://docs.base.org
- Check ARCHITECTURE.md for technical details
- Search GitHub issues
- Join Discord (link in README)
- Email support@unlock.xyz
Happy building! The web is waiting to be unlocked. 🔓