Skip to content

Tgemayel/x402-sinatra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

x402 Sinatra

A Ruby Sinatra implementation of a x402 server.

Financial Datasets

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.

Prerequisites

  • Ruby 2.7+
  • Bundler

Setup

  1. Install dependencies:

    bundle install
  2. 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.

Usage

Start the server:

bundle exec rackup

Server runs on http://localhost:9292 (or 4567 depending on how you run it).

Endpoints

1. Crypto Snapshot

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"

2. Crypto Historical

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"

Response format

If no payment header is provided, the server returns a 402 Payment Required:

{
  "schemes": [
    {
      "scheme": "exact",
      "price": "$0.001",
      "network": "eip155:84532",
      "payTo": "0x..."
    },
    ...
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages