Package: chainlink-web3
Web3.py Chainlink LibraryTheWeb3.py Chainlink Libraryis a Chainlink Python library designed to simplify the interaction with Chainlink Ethereum contracts. It provides an easy and streamlined way to retrieve real-time prices using the Chainlink price oracle. The library is dependent onWeb3.py, so you'll need to provide an active instance during initialization.Once initialized, you can make use of theget_pricefunction. This function essentially invokes thelatestRoundDatafunction on the Chainlink price feed contract. As a result, theget_pricefunction returns aPriceobject containing all the data retrieved from the blockchain call.This library empowers Python developers by eliminating the need to write complex blockchain calls directly. Instead, it enables them to leverage the Chainlink price feed in a more familiar and simple manner.Table of contentPrerequisitesInstallationUsing this libraryInstalling web3.pyUsage examplePlugin MethodsPrice Feed Addressesget_priceFound an issue or have a question or suggestionBuild & install locallyBuild with dockerUseful linksPrerequisitesPython 3.7.2+pipweb3.py 6.0.0+Installationpip3installchainlink-web3Using this libraryInstalling web3.pypip3 install web3Usage examplefromweb3importWeb3,HTTPProviderfromchainlink_web3.utilsimportChainlinkUtils,typesw3=Web3(HTTPProvider('https://rpc.ankr.com/eth',request_kwargs={'timeout':180}))chainlink=ChainlinkUtils(w3=w3)result=chainlink.get_price(types.MAINNET_PRICE_FEEDS['LinkEth'])print(result)Plugin MethodsPrice Feed AddressesIncluded in this library are two dicts that contain the Ethereum contract addresses for specific token pairs:MAINNET_PRICE_FEEDSandSEPOLIA_PRICE_FEEDS. If you cannot find your desired price feed within these dicts, please checkhereto make sure it's supported, and if it is, please open an issue or a pull request for the missing price feed so that it can be added to the appropriate dict.get_pricedefget_price(self,price_feed_address:str,aggregator_interface_abi:list=None)->types.Price:# class Price:#     roundId: str#     answer: str#     startedAt: str#     updatedAt: str#     answeredInRound: straggregator_interface_abican be foundhere.Theget_pricemethod, accepts evm address for it's first parameter, and an optional second parameter for specifying the Chainlink Aggregator Interface ABI of the Ethereum smart contract you'd like to interact with (the parameter is defaulted toaggregator_interface_abi).Under the hood, this method is calling thelatestRoundDatafor the specified price feed, more information about it can be foundhere.fromweb3importWeb3,HTTPProviderfromchainlink_web3.utilsimportChainlinkUtils,typesw3=Web3(HTTPProvider('https://rpc.ankr.com/eth',request_kwargs={'timeout':180}))chainlink=ChainlinkUtils(w3=w3)result=chainlink.get_price(types.MAINNET_PRICE_FEEDS['LinkEth'])# Price(#     roundId=36893488147419106338,#     answer=164576918062797,#     startedAt=1697700215,#     updatedAt=1697700215,#     answeredInRound=36893488147419106338# )Found an issue or have a question or suggestionIf you found an issue or have a question or suggestionsubmit an issueor join us onDiscordBuild & install locallyClone repoInstall dependenciespip3installwheel
pip3installsetuptools
pip3installtwineRun the testspython3setup.pypytestGenerate .whl file for external usepython3setup.pybdist_wheelThis creates a./distfolder that contains a.whlfile.Use the bellow command to install the lib on your local environment:pip3install/path/to/wheelfile.whlBuild with dockerClone repoCreate docker imagechmod+x./run-docker.sh
./run-docker.shinstallTest lib./run-docker.shtestGenerate .whl file for external use./run-docker.shbuildThis creates a./distfolder that contains a.whlfile.Use the bellow command to install the lib on your local environment:pip3install/path/to/wheelfile.whlUseful linksweb3.py DocumentationChainlink Documentation