Skip to main content

Chainlink Price Feeds

Query Chainlink AggregatorV3 price feeds for real-time asset pricing and deploy price feed consumers with staleness detection.

When to Use

  • Portfolio valuation — convert token balances to USD in real time
  • DeFi pricing — price assets for lending, swaps, or liquidation logic
  • Staleness detection — reject stale prices in time-sensitive operations
  • Verifiable randomness — use Chainlink VRF for on-chain lotteries, gameplay, and fair distribution

List Available Price Feeds

const feeds = await urblock.chainlink.listPriceFeeds({
network: "polygon_amoy",
});

for (const feed of feeds.data) {
console.log(feed.pair, feed.feed_address);
}

Get Latest Price

const price = await urblock.chainlink.getPriceFeed("ETH/USD", {
network: "polygon_amoy",
});

console.log(price.price); // "234567000000" (8 decimals)
console.log(price.decimals); // 8
console.log(price.updated_at); // timestamp

Get Historical Rounds

const rounds = await urblock.chainlink.getPriceFeedRounds("ETH/USD", {
network: "polygon_amoy",
count: 10,
});

for (const round of rounds.data) {
console.log(round.round_id, round.price, round.updated_at);
}

Get Feed Configuration

const config = await urblock.chainlink.getPriceFeedConfig("ETH/USD", {
network: "polygon_amoy",
});

console.log(config.decimals); // 8
console.log(config.description); // "ETH / USD"

Deploy a Price Feed Consumer

Deploy a contract that reads from a Chainlink price feed with staleness detection:

const consumer = await urblock.chainlink.deployPriceFeedConsumer({
name: "ETH Price Consumer",
pair: "ETH/USD",
network: "polygon_amoy",
price_feed_address: "0xChainlinkFeedAddress...",
max_age_seconds: 3600, // reject prices older than 1 hour
idempotency_key: "price-consumer-001",
});

Update Staleness Threshold

await urblock.chainlink.updatePriceFeedMaxAge("ETH/USD", {
max_age_seconds: 7200, // 2 hours
network: "polygon_amoy",
idempotency_key: "max-age-001",
});

Request verifiable random numbers on-chain:

Deploy a VRF Consumer

const consumer = await urblock.chainlink.deployVrfConsumer({
name: "My VRF Consumer",
network: "polygon_amoy",
vrf_coordinator: "0xVrfCoordinatorAddress...",
subscription_id: "12345",
key_hash: "0x...",
callback_gas_limit: 100000,
request_confirmations: 3,
idempotency_key: "vrf-consumer-001",
});

Request Random Numbers

const request = await urblock.chainlink.createVrfRequest({
consumer_id: consumer.id,
num_words: 2,
network: "polygon_amoy",
idempotency_key: "vrf-001",
});

Get VRF Result

const result = await urblock.chainlink.getVrfResult(request.id);
console.log(result.random_words); // ["123...", "456..."]
console.log(result.fulfilled); // true

curl Example

# List available feeds
curl https://api.urblock.io/v1/price_feeds?network=polygon_amoy \
-H "Authorization: Bearer sk_test_..."

# Get latest ETH/USD price
curl https://api.urblock.io/v1/price_feeds/ETH%2FUSD?network=polygon_amoy \
-H "Authorization: Bearer sk_test_..."

Next Steps