Real-time cryptocurrency price oracle
- Historical sync - backfills price history from contract deployment block up to the current state
- Fetches BTC/ETH/LINK prices from CoinGecko every minute
- Updates smart contract when price differs >2% from on-chain AND <20% from Chainlink
- Streams contract price changes (all sources) via WebSocket
- Serves current prices, time-range history, history of reverts
- Zero reverts - prevents gas waste by pre-TX validation and by waiting previously sent TX for chosen symbol to be completed
- Multi-instance ready - easy to add distributed lock coordination to keep contract reverts at zero when multiple instances are running at the same time
- Extensible - easy to add new symbols (BTC/ETH/LINK/...) when contract supports it
- Rate limited RPC & API usage - protects external calls (CoinGecko, Ankr RPC..) from hitting provider limits
- Isolated rate limits per usage - separate limiters for app production mode and sync process (supports different API keys)
Create .env file in root directory
ANKR_SEPOLIA_API_KEY=your_ankr_key
ANKR_SEPOLIA_SYNC_API_KEY=your_2_ankr_key
COINGECKO_API_KEY=your_coingecko_key
WSS_URL=wss://eth-sepolia.g.alchemy.com/v2/your_key
CONTRACT_ADDR=0x0A7cF8518Eca70cfe64Ff9B28Cb0D8162F31A41D
DEPLOYMENT_BLOCK=10588291
PRIVATE_KEY=0xabcdef... # 64 hex chars (no 0x prefix)go mod tidy
go run app/main.go| Endpoint | Method | Description |
|---|---|---|
/api/v1/prices/:symbol |
GET |
Current prices (on-chain+CL+CG) |
/api/v1/prices/:symbol/last |
GET |
Last N prices (?n=10) |
/api/v1/prices/:symbol/range |
POST |
Time range query for prices |
/api/v1/reverts |
GET |
Revert history (?n=100) |
/api/v1/health |
GET |
Server status |
- Go 1.25.0
- Gin
- Ethereum Sepolia
- Solidity ^0.8.20
- go-ethereum
- Alchemy WSS
- WebSockets streaming
- Ankr Sepolia
- CoinGecko API
- Chainlink Price Feeds
- Storage: In-memory FIFO
- Rate Limiting
- Concurrency
- Testing (mocks / dependency injection)