back to main documentation

Overview

Gasnet currently stores estimates in the form of values representing facts about chain’s gas market or estimates for future prices. The values for a specific chain and timestamp has the following structure:

interface OraclePayload {
	height: bigint
	timestamp: bigint
	systemid: number
	chainid: bigint
	payloads: Array<OracleRecord>
}

Each OraclePayload contains a specific typ and its associated value :

interface OracleRecord {
	typ: number
	value: string
}

The typ identifies the meaning of the value. It can be a fact about the chain’s gas market (e.g. base fee) or an estimate for future price to settle on that chain (e.g. 90% confidence for inclusion in next 10 seconds).

Additional estimate values will be added to accommodate chain specific mechanics, such as blob pricing. Gas estimates are available for all the chains currently support by the Blocknative Gas API. The complete list of available chains is listed in the API docs available here: https://docs.blocknative.com/gas-prediction/gas-platform

Fetch Gasnet Estimation Data

The following code will fetch a gas estimate from Gasnet using Ethers in Typescript:

const GASNET_URL=https://test.devnet.gas.network
const GASNET_CONTRACT_ADDRESS = '0x106A0e60fb930b96BDF9da93997747601435e1d9'

const gasnetProvider = new ethers.JsonRpcProvider(GASNET_URL);
const gasnetContract = new ethers.Contract(
  GASNET_CONTRACT_ADDRESS,
  abi,
  gasnetProvider
); 

const payload = await gasnetContract.getValues('2', '1') // get estimates for Ethereum (chain  id 1)

This estimate containing the supported values for the specified chain includes a signature that the Gasnet Pull Oracle on the Consumer Chain uses to verify the integrity of the estimate.

Update Consumer Chain Oracle

Once a gas estimation is retrieved from Gasnet above, the following sample code puts the data on the Consumer Chain with the Pull Oracle using Ethers in Typescript:

<aside> 💡

Currently the Pull Oracle contract is deployed to the following networks. More will be added soon.

</aside>

Mainnet

// Arbitrum One
export const CONSUMER_CHAIN_URL=https://arbitrum.llamarpc.com
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

// Base
export const CONSUMER_CHAIN_URL=https://base.llamarpc.com
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

// Ethereum
export const CONSUMER_CHAIN_URL=https://eth.llamarpc.com
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

// Linea
export const CONSUMER_CHAIN_URL=https://rpc.linea.build
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

// Optimism
export const CONSUMER_CHAIN_URL=https://optimism.llamarpc.com
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

// Unichain
export const CONSUMER_CHAIN_URL=https://mainnet.unichain.org
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x2c84370DaddBcD67d729689671A9Fe63DF39Cf13'

Testnet

// Base Sepolia
export const CONSUMER_CHAIN_URL=https://sepolia.base.org
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0xD87f5Ea40C592DfFAe5B87922E1cdA2bb44CB67F'

// Ethereum Sepolia
export const CONSUMER_CHAIN_URL=https://endpoints.omniatech.io/v1/eth/sepolia/public
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0xCc936bE977BeDb5140C5584d8B6043C9068622A6'

// Linea Sepolia
export const CONSUMER_CHAIN_URL=https://linea-sepolia-rpc.publicnode.com
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0xb690C4CbDE4747FD614477Ab24c7630C5aAa6Ec5'

// Optimism Sepolia
export const CONSUMER_CHAIN_URL=https://sepolia.optimism.io
export const CONSUMER_CHAIN_CONTRACT_ADDRESS = '0x20A5DCE3646BD975edEE3082319bd0dB64A0e0B9'
	async function publishGasEstimation(provider: any) {
		try {
			const { ethers } = await loadEthers()
			const ethersProvider = new ethers.BrowserProvider(provider, 'any')
			const signer = await ethersProvider.getSigner()

			const consumerContract = new ethers.Contract(contractAddress, abi, signer)

			let transaction = await consumerContract.storeValues(payload)

			const receipt = await transaction.wait()
			console.info('Publication success:', receipt.hash)
		} catch (error) {
			const revertErrorFromGasNetContract = (error as any)?.info?.error?.message
			console.error('Publication error:', error)
		}
	}