End-to-end demo showing how to consume Chainlink-compatible price feeds on Somnia Testnet.
- Node.js >= 18, npm >= 9
- A funded Somnia Testnet EOA (get STT test tokens via the faucet)
- PRIVATE_KEY for that EOA
- Chain ID: 50312
- Symbol: STT
- RPC (official):
https://dream-rpc.somnia.network
(alt:https://50312.rpc.thirdweb.com
) - Explorer:
https://shannon-explorer.somnia.network
- ETH/USD:
0xd9132c1d762D432672493F640a63B758891B449e
- BTC/USD:
0x8CeE6c58b8CbD8afdEaF14e6fCA0876765e161fE
- USDC/USD:
0xa2515C9480e62B510065917136B08F3f7ad743B4
Always verify addresses in the official docs before using in production.
npm install
cp .env.example .env
# edit .env: set SOMNIA_RPC and PRIVATE_KEY
npx hardhat compile
# 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.
# 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.
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>
- The
PriceConsumer
exposesgetLatest()
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.