Real-time cryptocurrency price oracle
- Fetches BTC/ETH 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/SOL/...) when contract supports it
Create .env file in root directory
ANKR_SEPOLIA_API_KEY=your_ankr_key
WSS_URL=wss://eth-sepolia.g.alchemy.com/v2/your_key
CONTRACT_ADDR=0xFf0fCE651EB5C7C147Af111f89dCB25AB57407e8
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
- Ankr Sepolia
- CoinGecko API
- Chainlink Price Feeds
- Storage: In-memory FIFO