A Ruby Sinatra implementation of a x402 server.
Rack middleware (X402::Middleware) to handle payments and verification on EVM (Base Sepolia) and SVM (Solana Devnet). Protected endpoints that fetch data from Financial Datasets.
- Ruby 2.7+
- Bundler
-
Install dependencies:
bundle install
-
Environment Configuration: Copy the example environment file and update it with your keys.
cp .env.example .env
You will need:
FINANCIAL_DATASETS_API_KEY: Get one from financialdatasets.ai.FACILITATOR_URL: URL of your x402 facilitator.EVM_ADDRESS/SVM_ADDRESS: Your wallet addresses for receiving payments.
Start the server:
bundle exec rackupServer runs on http://localhost:9292 (or 4567 depending on how you run it).
Get the latest price for a ticker.
- Price: $0.001
- Path:
/crypto/snapshot - Params:
ticker(e.g.,BTC-USD)
Example:
curl -v "http://localhost:4567/crypto/snapshot?ticker=BTC-USD"Get historical price data.
- Price: $0.01
- Path:
/crypto/historical - Params:
ticker,start_date,end_date,interval
Example:
curl -v "http://localhost:4567/crypto/historical?ticker=BTC-USD&start_date=2025-01-01&end_date=2025-01-02&interval=hour"If no payment header is provided, the server returns a 402 Payment Required:
{
"schemes": [
{
"scheme": "exact",
"price": "$0.001",
"network": "eip155:84532",
"payTo": "0x..."
},
...
]
}