Package: ankr-sdk
⚓️ Ankr Python SDKCompact Python library for interacting with Ankr'sAdvanced APIs.Get started in 2 minutes1. Install the package from PyPipipinstallankr-sdk2. Initialize the SDKNote: to use Advanced API for free starting from May 29th, 2023 you have to register on the platform.Get your individual endpoint herehttps://www.ankr.com/rpc/advanced-apiand provide it to theAnkrWeb3class.fromankrimportAnkrWeb3ankr_w3=AnkrWeb3("YOUR-TOKEN")3. Use the sdk and call one of the supported methodsNode's APIfromankrimportAnkrWeb3ankr_w3=AnkrWeb3("YOUR-TOKEN")eth_block=ankr_w3.eth.get_block("latest")bsc_block=ankr_w3.bsc.get_block("latest")polygon_block=ankr_w3.polygon.get_block("latest")Ankr NFT APIfromankrimportAnkrWeb3fromankr.typesimportBlockchain,GetNFTsByOwnerRequestankr_w3=AnkrWeb3("YOUR-TOKEN")nfts=ankr_w3.nft.get_nfts(request=GetNFTsByOwnerRequest(blockchain=Blockchain.Eth,walletAddress="0x0E11A192d574b342C51be9e306694C41547185DD"))Ankr Token APIfromankrimportAnkrWeb3fromankr.typesimportGetAccountBalanceRequestankr_w3=AnkrWeb3("YOUR-TOKEN")assets=ankr_w3.token.get_account_balance(request=GetAccountBalanceRequest(walletAddress="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"))Ankr Query APIfromankrimportAnkrWeb3fromankr.typesimportBlockchain,GetLogsRequestankr_w3=AnkrWeb3("YOUR-TOKEN")logs=ankr_w3.query.get_logs(request=GetLogsRequest(blockchain=[Blockchain.Eth],fromBlock=1181739,toBlock=1181739,address=["0x3589d05a1ec4af9f65b0e5554e645707775ee43c"],topics=[[],["0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec"],],decodeLogs=True,),limit=10)Ankr Advanced APIs supported chainsankr-sdksupports the following chains at this time:MainnetEthereum:"eth"BNB Smart Chain:"bsc"Polygon:"polygon"Fantom:"fantom"Arbitrum:"arbitrum"Avalanche:"avalanche"Syscoin NEVM:"syscoin"Optimism:"optimism"Polygon zkEVM:"polygon_zkevm"Rollux:"rollux"Base:"base"Flare:"flare"Gnosis Chain:"gnosis"Scroll:"scroll"Linea:"linea"TestnetEthereum Goerli:"eth_goerli"Avalanche Fuji:"avalanche_fuji"Polygon Mumbai:"polygon_mumbai"Optimism Testnet:"optimism_testnet"AppchainMETA Apes:"bas_metaapes"Appchain TestnetMETA Apes Testnet:"bas_metaapes_testnet"When passing blockchain, you can use one available fromtypes.py(preferred) or just a string value.Available methodsankr-sdksupports the following methods:Early Accessget_token_price_historyget_account_balance_historicalget_internal_transactions_by_block_numberget_internal_transactions_by_parent_hashToken APIexplain_token_priceget_account_balanceget_currenciesget_token_holdersget_token_holders_count_historyget_token_holders_countget_token_priceget_token_transfersNFT APIget_nftsget_nft_metadataget_nft_holdersget_nft_transfersQuery APIget_logsget_blocksget_transactionget_transactions_by_addressget_blockchain_statsget_interactionsNote: some methods are available in *_raw format, allowing to get full reply with syncStatus and control pagination by hands.Paginationmethods with *_raw ending support customized pagination, where you are controlling it, usingpageSizeandpageTokenother methods support automatic pagination, DON'T usepageSizeandpageTokenfields to these methodsExamplesEarly Access APIget_token_price_history/get_token_price_history_rawGet a list of history of the price for given contract to given timestamp.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTokenPriceHistoryRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_price_history(request=GetTokenPriceHistoryRequest(blockchain=Blockchain.Eth,contractAddress='0x50327c6c5a14dcade707abad2e27eb517df87ab5',toTimestamp=1696970653,interval=100,limit=10))print(result)get_account_balance_historical/get_account_balance_historical_rawGet the coin and token balances of the wallet at specified block.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetAccountBalanceHistoricalRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_account_balance_historical(request=GetAccountBalanceHistoricalRequest(blockchain=Blockchain.Eth,walletAddress='vitalik.eth',onlyWhitelisted=False,blockHeight=17967813,))print(result)get_internal_transactions_by_block_number/get_internal_transactions_by_block_number_rawGet a list of internal transactions in the block.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetInternalTransactionsByBlockNumberRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_internal_transactions_by_block_number(request=GetInternalTransactionsByBlockNumberRequest(blockchain=Blockchain.Eth,blockNumber=10000000,onlyWithValue=True,))fortransactioninresult:print(transaction)get_internal_transactions_by_parent_hash/get_internal_transactions_by_parent_hash_rawGet a list of internal transactions in the transaction.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetInternalTransactionsByParentHashRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_internal_transactions_by_parent_hash(request=GetInternalTransactionsByParentHashRequest(blockchain=Blockchain.Eth,parentTransactionHash='0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5',onlyWithValue=True,))fortransactioninresult:print(transaction)Token APIexplain_token_price/explain_token_price_rawGet a list of tokens and pool how price for calculated.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,ExplainTokenPriceRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")pairs,estimates=advancedAPI.explain_token_price(request=ExplainTokenPriceRequest(blockchain=Blockchain.Eth,tokenAddress='0x8290333cef9e6d528dd5618fb97a76f268f3edd4',blockHeight=17463534,))print(pairs)print(estimates)get_account_balance/get_account_balance_rawGet the coin and token balances of a wallet.fromankrimportAnkrAdvancedAPIfromankr.typesimportGetAccountBalanceRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_account_balance(request=GetAccountBalanceRequest(walletAddress="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"))forbalanceinresult:print(balance)get_currencies/get_currencies_rawGet a list of supported currencies for a given blockchain.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetCurrenciesRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_currencies(request=GetCurrenciesRequest(blockchain=Blockchain.Fantom,))forcurrencyinresult:print(currency)get_token_holders/get_token_holders_rawGet the list of token holders for a given contract address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTokenHoldersRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_holders(request=GetTokenHoldersRequest(blockchain=Blockchain.Eth,contractAddress='0xdac17f958d2ee523a2206206994597c13d831ec7',))forbalanceinresult:print(balance)get_token_holders_count_history/get_token_holders_count_history_rawGet historical data about the number of token holders for a given contract address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTokenHoldersCountRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_holders_count_history(request=GetTokenHoldersCountRequest(blockchain=Blockchain.Eth,contractAddress='0xdAC17F958D2ee523a2206206994597C13D831ec7',))forbalanceinresult:print(balance)get_token_holders_count/get_token_holders_count_rawGet current data about the number of token holders for a given contract address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTokenHoldersCountRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_holders_count_history_raw(request=GetTokenHoldersCountRequest(blockchain=Blockchain.Eth,contractAddress='0xdAC17F958D2ee523a2206206994597C13D831ec7',))print(result)get_token_price/get_token_price_rawGet token price by contract.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTokenPriceRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_price(request=GetTokenPriceRequest(blockchain=Blockchain.Eth,contractAddress='',))print(result)get_token_transfers/get_token_transfers_rawGet token transfers of specified address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTransfersRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_token_transfers(request=GetTransfersRequest(blockchain=Blockchain.Eth,address=['0xf16e9b0d03470827a95cdfd0cb8a8a3b46969b91'],fromTimestamp=1674441035,toTimestamp=1674441035,descOrder=True,))fortransferinresult:print(transfer)NFT APIget_nfts/get_nfts_rawGet data about all the NFTs (collectibles) owned by a wallet.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetNFTsByOwnerRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_nfts(request=GetNFTsByOwnerRequest(blockchain=Blockchain.Eth,walletAddress='0x0E11A192d574b342C51be9e306694C41547185DD',))fornftinresult:print(nft)get_nft_metadata/get_nft_metadata_rawGet NFT's contract metadata.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetNFTMetadataRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")reply=advancedAPI.get_nft_metadata(request=GetNFTMetadataRequest(blockchain=Blockchain.Eth,contractAddress='0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',tokenId='1500',forceFetch=False,))print(reply.metadata)print(reply.attributes)get_nft_holders/get_nft_holders_rawGet NFT's holders.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetNFTHoldersRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_nft_holders(request=GetNFTHoldersRequest(blockchain=Blockchain.Arbitrum,contractAddress='0xc36442b4a4522e871399cd717abdd847ab11fe88',),limit=1000)forholderinresult:print(holder)get_nft_transfers/get_nft_transfers_rawGet NFT Transfers of specified address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTransfersRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_nft_transfers(request=GetTransfersRequest(blockchain=[Blockchain.Eth,Blockchain.Bsc],address=['0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],fromTimestamp=1672553107,toTimestamp=1672683207,))fortransferinresult:print(transfer)Query APIget_logs/get_logs_rawGet logs matching the filter.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetLogsRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_logs(request=GetLogsRequest(blockchain=[Blockchain.Eth],fromBlock=1181739,toBlock=1181739,address=["0x3589d05a1ec4af9f65b0e5554e645707775ee43c"],topics=[[],["0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec"],],decodeLogs=True,),limit=10)forloginresult:print(log)get_blocks/get_blocks_rawQuery data about blocks within a specified range.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetBlocksRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_blocks(request=GetBlocksRequest(blockchain=Blockchain.Eth,fromBlock=14500001,toBlock=14500004,descOrder=True,includeLogs=True,includeTxs=True,decodeLogs=True,))forblockinresult:print(block)get_transaction/get_transaction_rawQuery data about transaction by the transaction hash.fromankrimportAnkrAdvancedAPIfromankr.typesimportGetTransactionsByHashRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_transaction(request=GetTransactionsByHashRequest(transactionHash='0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f',decodeTxData=True))print(result)get_transactions_by_address/get_transactions_by_address_rawQuery data about transactions of specified address.fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetTransactionsByAddressRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_transactions_by_address(request=GetTransactionsByAddressRequest(blockchain=Blockchain.Bsc,fromBlock=23593283,toBlock=23593283,address=["0x97242e3315c7ece760dc7f83a7dd8af6659f8c4c"],descOrder=True,))fortransactioninresult:print(transaction)get_blockchain_stats/get_blockchain_stats_rawReturns blockchain stats (num of txs, etc.).fromankrimportAnkrAdvancedAPIfromankr.typesimportBlockchain,GetBlockchainStatsRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_blockchain_stats(request=GetBlockchainStatsRequest(blockchain=Blockchain.Bsc,))forstatinresult:print(stat)get_interactions/get_interactions_rawReturns on which chain address was interacting.fromankrimportAnkrAdvancedAPIfromankr.typesimportGetInteractionsRequestadvancedAPI=AnkrAdvancedAPI("YOUR-TOKEN")result=advancedAPI.get_interactions(request=GetInteractionsRequest(address='0xF977814e90dA44bFA03b6295A0616a897441aceC',))forblockchaininresult:print(blockchain)About API keysAnkr is offeringfreeaccess to Advanced API, however you have to register on Ankr platform to access it.Get your individual API Key herehttps://www.ankr.com/rpc/advanced-api.