An MCP (Model Context Protocol) server implementing the x402 payment protocol for paid Solidity compilation services using USDC on Base Sepolia.
This project demonstrates a complete x402 payment flow where:
- Client creates payment authorizations and settles them on-chain (pays gas fees)
- Server verifies payment settlement on-chain before providing services
- Payments are made in USDC using EIP-3009
TransferWithAuthorization
- Paid Solidity Compilation: Compile Solidity contracts using Remix compiler (0.5 USDC per compilation)
- x402 Payment Protocol: Fully compliant implementation with on-chain settlement verification
- USDC Payments: ERC-20 token payments on Base Sepolia testnet
- Custom Wallet: EIP-712 signature implementation for USDC compatibility
- MCP Integration: Built with Ampersend SDK for seamless payment-gated tools
src/client/index.js- MCP client setup and configurationsrc/client/treasurer.js- Handles payment authorization and on-chain settlementsrc/client/usdc-wallet.js- Custom wallet with USDC-compatible EIP-712 signatures
src/server/index.ts- MCP server with payment-gated tools- Verifies payment settlement on-chain before executing compilation
- Node.js (v18 or higher)
- USDC on Base Sepolia testnet
- Private key for your wallet
# Install dependencies
npm install
# or
yarn install- Create a
.envfile in the project root:
# Your wallet private key (DO NOT commit this!)
PRIVATE_KEY=0x...
# Address where payments should be sent (server owner's address)
PAY_TO_ADDRESS=0x...- Get testnet USDC
# Build TypeScript files
npm run build
# or
yarn buildyarn startThe server will start on http://localhost:8000/mcp
yarn run clientThe client will:
- Connect to the MCP server
- Request the
compile_soliditytool - Receive a 402 Payment Required response
- Create a USDC payment authorization
- Settle the payment on-chain (client pays gas)
- Re-request with payment proof
- Server verifies settlement on-chain
- Compilation executes and returns results
Client Server
| |
|---(1) Request Tool----------->|
| |
|<--(2) 402 Payment Required----|
| |
|---(3) Create Authorization--->|
| |
|---(4) Settle On-Chain-------->| (Blockchain)
| |
|---(5) Re-request with Proof-->|
| |
| (6) Verify Settlement
| |
|<--(7) Execute & Return--------|
Compiles Solidity contracts using the Remix compiler.
Payment Required: 0.5 USDC (500000 with 6 decimals)
Parameters:
sources: Object with contract filenames as keys and their contentsettings(optional): Compiler settings (optimizer, evmVersion)
Example:
{
sources: {
"SimpleStorage.sol": {
content: "contract SimpleStorage { uint256 value; }"
}
},
settings: {
optimizer: { enabled: true, runs: 200 },
evmVersion: "london"
}
}- Network: Base Sepolia
- Chain ID: 84532
- USDC Contract:
0x036CbD53842c5426634e7929541eC2318f3dCF7e - RPC:
https://sepolia.base.org
- Never commit your private key
- Only use testnet funds for development
- The
.envfile is gitignored by default - Server verifies all payments on-chain before executing tools