Compact Python library for interacting with Ankr's Advanced APIs.
pip install ankr-sdk
Note: to use Advanced API for free starting from May 29th, 2023 you have to register on the platform.
Get your individual endpoint here https://www.ankr.com/rpc/advanced-api and provide it to the AnkrWeb3
class.
from ankr import AnkrWeb3
ankr_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")
from ankr.types import Blockchain
nfts = ankr_w3.nft.get_nfts(
blockchain=[Blockchain.ETH, Blockchain.BSC],
wallet_address="0x0E11A192d574b342C51be9e306694C41547185DD",
filter=[
{"0x700b4b9f39bb1faf5d0d16a20488f2733550bff4": []},
{"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": ["8937"]},
],
)
assets = ankr_w3.token.get_account_balance(
wallet_address="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"
)
logs = ankr_w3.query.get_logs(
blockchain="eth",
from_block="0xdaf6b1",
to_block=14350010,
address=["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"],
topics=[
[],
["0x000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff"],
],
decode_logs=True,
)
ankr-sdk
supports the following chains at this time:
- ETH:
"eth"
- BSC:
"bsc"
- Polygon:
"polygon"
- Fantom:
"fantom"
- Arbitrum:
"arbitrum"
- Avalanche:
"avalanche"
- Syscoin NEVM:
"syscoin"
ankr-sdk
supports the following methods:
nft.get_nfts
nft.get_nft_metadata
nft.get_nft_holders
token.get_token_holders
token.get_token_holders_count_history
token.get_token_holders_count
token.get_token_price
token.get_account_balance
query.get_logs
query.get_blocks
query.get_transaction
Get data about all the NFTs (collectibles) owned by a wallet.
nfts = ankr_w3.nft.get_nfts(
blockchain="eth",
wallet_address="0x0E11A192d574b342C51be9e306694C41547185DD",
filter=[
{"0x700b4b9f39bb1faf5d0d16a20488f2733550bff4": []},
{"0xd8682bfa6918b0174f287b888e765b9a1b4dc9c3": ["8937"]},
],
)
Get metadata of NFT.
nfts = ankr_w3.nft.get_nft_metadata(
blockchain="eth",
contract_address="0x4100670ee2f8aef6c47a4ed13c7f246e621228ec",
token_id="4",
)
Get holders of a token.
holders = ankr_w3.token.get_token_holders(
blockchain="bsc",
contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
limit=10,
)
Get token holders count daily history.
daily_holders_history = ankr_w3.token.get_token_holders_count_history(
blockchain="bsc",
contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
limit=10, # last 10 days history
)
Get token holders count at the latest block.
holders_count = ankr_w3.token.get_token_holders_count(
blockchain="bsc",
contract_address="0xf307910A4c7bbc79691fD374889b36d8531B08e3",
)
Get account assets.
assets = ankr_w3.token.get_account_balance(
wallet_address="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527",
blockchain=["eth", "bsc"],
)
Get logs matching the filter.
logs = ankr_w3.query.get_logs(
blockchain="eth",
from_block="0xdaf6b1",
to_block=14350010,
address=["0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"],
topics=[
[],
["0x000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25eff"],
],
decode_logs=True,
)
Query data about blocks within a specified range.
blocks = ankr_w3.query.get_blocks(
blockchain="eth",
from_block=14500001,
to_block=14500001,
desc_order=True,
include_logs=True,
include_txs=True,
decode_logs=True,
)
Get Transaction by hash.
tx = ankr_w3.query.get_transaction(
transaction_hash="0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f",
include_logs=True,
decode_logs=True,
decode_tx_data=True,
)
Ankr is offering free access to Advanced API, however you have to register on Ankr platform to access it.
Get your individual API Key here https://www.ankr.com/rpc/advanced-api.