get_native_token_price_with_chainlink
Documentation for eth_defi.chainlink.token_price.get_native_token_price_with_chainlink function.
- get_native_token_price_with_chainlink(web3)[source]
Get the latest price of a native token on any chain in USD.
Example for ETH:
import os from eth_defi.chainlink.token_price import get_native_token_price_with_chainlink from eth_defi.provider.multi_provider import create_multi_provider_web3 json_rpc_url = os.environ["JSON_RPC_URL"] web3 = create_multi_provider_web3(json_rpc_url) token_name, last_round = get_native_token_price_with_chainlink(web3) price = last_round.price print(f"The chain native token price of is {price} {token_name} / USD")
- Returns
USD exchange rate of the chain native token.
Returned as native token symbol, latest ChainLink round data.
- Raises
NotImplementedError – Chainlink configuration not yet added for this chain.
- Parameters
web3 (web3.main.Web3) –
- Return type
Tuple[str, eth_defi.chainlink.round_data.ChainLinkLatestRoundData]