Skip to content

protofire/somnia-price-feeds

Repository files navigation

Somnia Price Feeds Demo (Hardhat)

End-to-end demo showing how to consume Chainlink-compatible price feeds on Somnia Testnet.

Prerequisites

  • Node.js >= 18, npm >= 9
  • A funded Somnia Testnet EOA (get STT test tokens via the faucet)
  • PRIVATE_KEY for that EOA

Network (Somnia Testnet)

  • Chain ID: 50312
  • Symbol: STT
  • RPC (official): https://dream-rpc.somnia.network (alt: https://50312.rpc.thirdweb.com)
  • Explorer: https://shannon-explorer.somnia.network

Price Feed addresses (Somnia Testnet)

  • ETH/USD: 0xd9132c1d762D432672493F640a63B758891B449e
  • BTC/USD: 0x8CeE6c58b8CbD8afdEaF14e6fCA0876765e161fE
  • USDC/USD: 0xa2515C9480e62B510065917136B08F3f7ad743B4

Always verify addresses in the official docs before using in production.

Setup

npm install
cp .env.example .env
# edit .env: set SOMNIA_RPC and PRIVATE_KEY

Compile

npx hardhat compile

Deploy (Ignition)

# Example: deploy consumer wired to ETH/USD feed
npm run deploy:ethusd
# Or pick BTC/USD or USDC/USD
npm run deploy:btcusd
npm run deploy:usdcusd

The console will print the deployed PriceConsumer address. Copy it.

Read via Hardhat task

# From the consumer contract you just deployed:
npx hardhat demo --consumer <DEPLOYED_ADDRESS> --network somnia

# Or read a feed directly (no deployment needed):
npx hardhat price --feed 0xd9132c1d762D432672493F640a63B758891B449e --network somnia

Both commands print raw/normalized price and the last-updated timestamp.

Verify on Explorer

You can configure the Etherscan plugin to verify on Somnia’s explorer (shannon-explorer.somnia.network). See hardhat.config.ts for custom chain settings.

# Example (no constructor args for PriceConsumer)
npx hardhat verify --network somnia <DEPLOYED_ADDRESS>

Notes

  • The PriceConsumer exposes getLatest() that returns (price, updatedAt, decimals) for easy reading.
  • Arithmetic is NOT done on-chain here; do conversions in your app logic using the returned decimals.
  • Price feeds are Chainlink-compatible and provided by Protofire on Somnia Testnet.

About

demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published