ankr-sdk


Nameankr-sdk JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://ankr.com/
SummaryCompact Python library for interacting with Ankr's Advanced APIs.
upload_time2024-03-29 13:48:24
maintainerNone
docs_urlNone
authorRoman Fasakhov
requires_python<4.0.0,>=3.8.1
licenseMIT
keywords ankr sdk blockchain nft
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ⚓️ Ankr Python SDK

Compact Python library for interacting with Ankr's [Advanced APIs](https://www.ankr.com/advanced-api/).

## Get started in 2 minutes

#### 1. Install the package from PyPi

```bash
pip install ankr-sdk
```

#### 2. Initialize the 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.

```python3
from ankr import AnkrWeb3

ankr_w3 = AnkrWeb3("YOUR-TOKEN")
```

#### 3. Use the sdk and call one of the supported methods

#### Node's API
```python3
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")
```

#### Ankr NFT API 

```python3
from ankr import AnkrWeb3
from ankr.types import Blockchain, GetNFTsByOwnerRequest

ankr_w3 = AnkrWeb3("YOUR-TOKEN")

nfts = ankr_w3.nft.get_nfts(
    request=GetNFTsByOwnerRequest(
        blockchain=Blockchain.Eth,
        walletAddress="0x0E11A192d574b342C51be9e306694C41547185DD"
    )
)
```

#### Ankr Token API
```python3
from ankr import AnkrWeb3
from ankr.types import GetAccountBalanceRequest

ankr_w3 = AnkrWeb3("YOUR-TOKEN")

assets = ankr_w3.token.get_account_balance(
    request=GetAccountBalanceRequest(
        walletAddress="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"
    )
)
```

#### Ankr Query API
```python3
from ankr import AnkrWeb3
from ankr.types import Blockchain, GetLogsRequest

ankr_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 chains

`ankr-sdk` supports the following chains at this time:

Mainnet

- Ethereum: `"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"`

Testnet

- Ethereum Goerli: `"eth_goerli"`
- Avalanche Fuji: `"avalanche_fuji"`
- Polygon Mumbai: `"polygon_mumbai"`
- Optimism Testnet: `"optimism_testnet"`

Appchain

- META Apes: `"bas_metaapes"`

Appchain Testnet

- META Apes Testnet: `"bas_metaapes_testnet"`

When passing blockchain, you can use one available from `types.py` (preferred) or just a string value.  

## Available methods

`ankr-sdk` supports the following methods:

Early Access

- [`get_token_price_history`](#gettokenpricehistory--gettokenpricehistoryraw)
- [`get_account_balance_historical`](#getaccountbalancehistorical--getaccountbalancehistoricalraw)
- [`get_internal_transactions_by_block_number`](#getinternaltransactionsbyblocknumber--getinternaltransactionsbyblocknumberraw)
- [`get_internal_transactions_by_parent_hash`](#getinternaltransactionsbyparenthash--getinternaltransactionsbyparenthashraw)

Token API

- [`explain_token_price`](#explaintokenprice--explaintokenpriceraw)
- [`get_account_balance`](#getaccountbalance--getaccountbalanceraw)
- [`get_currencies`](#getcurrencies--getcurrenciesraw)
- [`get_token_holders`](#gettokenholders--gettokenholdersraw)
- [`get_token_holders_count_history`](#gettokenholderscounthistory--gettokenholderscounthistoryraw)
- [`get_token_holders_count`](#gettokenholderscount--gettokenholderscountraw)
- [`get_token_price`](#gettokenprice--gettokenpriceraw)
- [`get_token_transfers`](#gettokentransfers--gettokentransfersraw)

NFT API

- [`get_nfts`](#getnfts--getnftsraw)
- [`get_nft_metadata`](#getnftmetadata--getnftmetadataraw)
- [`get_nft_holders`](#getnftholders--getnftholdersraw)
- [`get_nft_transfers`](#getnfttransfers--getnfttransfersraw)

Query API

- [`get_logs`](#getlogs--getlogsraw)
- [`get_blocks`](#getblocks--getblocksraw)
- [`get_transaction`](#gettransaction--gettransactionraw)
- [`get_transactions_by_address`](#gettransactionsbyaddress--gettransactionsbyaddressraw)
- [`get_blockchain_stats`](#getblockchainstats--getblockchainstatsraw)
- [`get_interactions`](#getinteractions--getinteractionsraw)


Note: some methods are available in *_raw format, allowing to get full reply with syncStatus and control pagination by hands.

### Pagination

- methods with *_raw ending support customized pagination, where you are controlling it, using `pageSize` and `pageToken`
- other methods support automatic pagination, DON'T use `pageSize` and `pageToken` fields to these methods

---

## Examples

### Early Access API

#### `get_token_price_history` / `get_token_price_history_raw`

Get a list of history of the price for given contract to given timestamp.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTokenPriceHistoryRequest

advancedAPI = 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_raw`

Get the coin and token balances of the wallet at specified block.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetAccountBalanceHistoricalRequest

advancedAPI = 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_raw`

Get a list of internal transactions in the block.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetInternalTransactionsByBlockNumberRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_internal_transactions_by_block_number(
    request=GetInternalTransactionsByBlockNumberRequest(
        blockchain=Blockchain.Eth,
        blockNumber=10000000,
        onlyWithValue=True,
    )
)
for transaction in result:
    print(transaction)
```

#### `get_internal_transactions_by_parent_hash` / `get_internal_transactions_by_parent_hash_raw`

Get a list of internal transactions in the transaction.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetInternalTransactionsByParentHashRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_internal_transactions_by_parent_hash(
    request=GetInternalTransactionsByParentHashRequest(
        blockchain=Blockchain.Eth,
        parentTransactionHash='0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5',
        onlyWithValue=True,
    )
)
for transaction in result:
    print(transaction)
```

### Token API

#### `explain_token_price` / `explain_token_price_raw`

Get a list of tokens and pool how price for calculated.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, ExplainTokenPriceRequest

advancedAPI = 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_raw`

Get the coin and token balances of a wallet.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import GetAccountBalanceRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_account_balance(
    request=GetAccountBalanceRequest(
        walletAddress="0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527"
    )
)

for balance in result:
    print(balance)
```

#### `get_currencies` / `get_currencies_raw`

Get a list of supported currencies for a given blockchain.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetCurrenciesRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_currencies(
    request=GetCurrenciesRequest(
        blockchain=Blockchain.Fantom,
    )
)

for currency in result:
    print(currency)
```

#### `get_token_holders` / `get_token_holders_raw`

Get the list of token holders for a given contract address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTokenHoldersRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_token_holders(
    request=GetTokenHoldersRequest(
        blockchain=Blockchain.Eth,
        contractAddress='0xdac17f958d2ee523a2206206994597c13d831ec7',
    )
)

for balance in result:
    print(balance)
```

#### `get_token_holders_count_history` / `get_token_holders_count_history_raw`

Get historical data about the number of token holders for a given contract address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTokenHoldersCountRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_token_holders_count_history(
    request=GetTokenHoldersCountRequest(
        blockchain=Blockchain.Eth,
        contractAddress='0xdAC17F958D2ee523a2206206994597C13D831ec7',
    )
)

for balance in result:
    print(balance)
```

#### `get_token_holders_count` / `get_token_holders_count_raw`

Get current data about the number of token holders for a given contract address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTokenHoldersCountRequest

advancedAPI = 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_raw`

Get token price by contract.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTokenPriceRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_token_price(
    request=GetTokenPriceRequest(
        blockchain=Blockchain.Eth,
        contractAddress='',
    )
)

print(result)
```

#### `get_token_transfers` / `get_token_transfers_raw`

Get token transfers of specified address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTransfersRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_token_transfers(
    request=GetTransfersRequest(
        blockchain=Blockchain.Eth,
        address=['0xf16e9b0d03470827a95cdfd0cb8a8a3b46969b91'],
        fromTimestamp=1674441035,
        toTimestamp=1674441035,
        descOrder=True,
    )
)

for transfer in result:
    print(transfer)
```

### NFT API

#### `get_nfts` / `get_nfts_raw`

Get data about all the NFTs (collectibles) owned by a wallet.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetNFTsByOwnerRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_nfts(
    request=GetNFTsByOwnerRequest(
        blockchain=Blockchain.Eth,
        walletAddress='0x0E11A192d574b342C51be9e306694C41547185DD',
    )
)

for nft in result:
    print(nft)
```

#### `get_nft_metadata` / `get_nft_metadata_raw`

Get NFT's contract metadata.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetNFTMetadataRequest

advancedAPI = 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_raw`

Get NFT's holders.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetNFTHoldersRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_nft_holders(
    request=GetNFTHoldersRequest(
        blockchain=Blockchain.Arbitrum,
        contractAddress='0xc36442b4a4522e871399cd717abdd847ab11fe88',
    ),
    limit=1000
)

for holder in result:
    print(holder)
```

#### `get_nft_transfers` / `get_nft_transfers_raw`

Get NFT Transfers of specified address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTransfersRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_nft_transfers(
    request=GetTransfersRequest(
        blockchain=[Blockchain.Eth, Blockchain.Bsc],
        address=['0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],
        fromTimestamp=1672553107,
        toTimestamp=1672683207,
    )
)

for transfer in result:
    print(transfer)
```

### Query API

#### `get_logs` / `get_logs_raw`

Get logs matching the filter.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetLogsRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_logs(
    request=GetLogsRequest(
        blockchain=[Blockchain.Eth],
        fromBlock=1181739,
        toBlock=1181739,
        address=["0x3589d05a1ec4af9f65b0e5554e645707775ee43c"],
        topics=[
            [],
            ["0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec"],
        ],
        decodeLogs=True,
    ),
    limit=10
)

for log in result:
    print(log)
```

#### `get_blocks` / `get_blocks_raw`

Query data about blocks within a specified range.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetBlocksRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_blocks(
    request=GetBlocksRequest(
        blockchain=Blockchain.Eth,
        fromBlock=14500001,
        toBlock=14500004,
        descOrder=True,
        includeLogs=True,
        includeTxs=True,
        decodeLogs=True,
    )
)

for block in result:
    print(block)
```

#### `get_transaction` / `get_transaction_raw`

Query data about transaction by the transaction hash.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import GetTransactionsByHashRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_transaction(
    request=GetTransactionsByHashRequest(
        transactionHash='0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f',
        decodeTxData=True
    )
)

print(result)
```

#### `get_transactions_by_address` / `get_transactions_by_address_raw`

Query data about transactions of specified address.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetTransactionsByAddressRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_transactions_by_address(
    request=GetTransactionsByAddressRequest(
        blockchain=Blockchain.Bsc,
        fromBlock=23593283,
        toBlock=23593283,
        address=[
            "0x97242e3315c7ece760dc7f83a7dd8af6659f8c4c"
        ],
        descOrder=True,
    )
)

for transaction in result:
    print(transaction)
```

#### `get_blockchain_stats` / `get_blockchain_stats_raw`

Returns blockchain stats (num of txs, etc.).

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import Blockchain, GetBlockchainStatsRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_blockchain_stats(
    request=GetBlockchainStatsRequest(
        blockchain=Blockchain.Bsc,
    )
)

for stat in result:
    print(stat)
```

#### `get_interactions` / `get_interactions_raw`

Returns on which chain address was interacting.

```python3
from ankr import AnkrAdvancedAPI
from ankr.types import GetInteractionsRequest

advancedAPI = AnkrAdvancedAPI("YOUR-TOKEN")

result = advancedAPI.get_interactions(
    request=GetInteractionsRequest(
        address='0xF977814e90dA44bFA03b6295A0616a897441aceC',
    )
)

for blockchain in result:
    print(blockchain)
```



### About API keys

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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://ankr.com/",
    "name": "ankr-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.8.1",
    "maintainer_email": null,
    "keywords": "ankr, sdk, blockchain, nft",
    "author": "Roman Fasakhov",
    "author_email": "romanfasakhov@ankr.com",
    "download_url": "https://files.pythonhosted.org/packages/9a/56/d281d421e08f1ed2f22e7b2a7e21cd7e3e58478a9bce5f0f1cf222407ed5/ankr_sdk-1.0.1.tar.gz",
    "platform": null,
    "description": "# \u2693\ufe0f Ankr Python SDK\n\nCompact Python library for interacting with Ankr's [Advanced APIs](https://www.ankr.com/advanced-api/).\n\n## Get started in 2 minutes\n\n#### 1. Install the package from PyPi\n\n```bash\npip install ankr-sdk\n```\n\n#### 2. Initialize the SDK\n\n_Note: to use Advanced API for free starting from May 29th, 2023 you have to register on the platform._\n\nGet your individual endpoint here https://www.ankr.com/rpc/advanced-api and provide it to the `AnkrWeb3` class.\n\n```python3\nfrom ankr import AnkrWeb3\n\nankr_w3 = AnkrWeb3(\"YOUR-TOKEN\")\n```\n\n#### 3. Use the sdk and call one of the supported methods\n\n#### Node's API\n```python3\nfrom ankr import AnkrWeb3\nankr_w3 = AnkrWeb3(\"YOUR-TOKEN\")\n\neth_block = ankr_w3.eth.get_block(\"latest\")\nbsc_block = ankr_w3.bsc.get_block(\"latest\")\npolygon_block = ankr_w3.polygon.get_block(\"latest\")\n```\n\n#### Ankr NFT API \n\n```python3\nfrom ankr import AnkrWeb3\nfrom ankr.types import Blockchain, GetNFTsByOwnerRequest\n\nankr_w3 = AnkrWeb3(\"YOUR-TOKEN\")\n\nnfts = ankr_w3.nft.get_nfts(\n    request=GetNFTsByOwnerRequest(\n        blockchain=Blockchain.Eth,\n        walletAddress=\"0x0E11A192d574b342C51be9e306694C41547185DD\"\n    )\n)\n```\n\n#### Ankr Token API\n```python3\nfrom ankr import AnkrWeb3\nfrom ankr.types import GetAccountBalanceRequest\n\nankr_w3 = AnkrWeb3(\"YOUR-TOKEN\")\n\nassets = ankr_w3.token.get_account_balance(\n    request=GetAccountBalanceRequest(\n        walletAddress=\"0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527\"\n    )\n)\n```\n\n#### Ankr Query API\n```python3\nfrom ankr import AnkrWeb3\nfrom ankr.types import Blockchain, GetLogsRequest\n\nankr_w3 = AnkrWeb3(\"YOUR-TOKEN\")\n\nlogs = ankr_w3.query.get_logs(\n    request=GetLogsRequest(\n        blockchain=[Blockchain.Eth],\n        fromBlock=1181739,\n        toBlock=1181739,\n        address=[\"0x3589d05a1ec4af9f65b0e5554e645707775ee43c\"],\n        topics=[\n            [],\n            [\"0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec\"],\n        ],\n        decodeLogs=True,\n    ),\n    limit=10\n)\n```\n\n## Ankr Advanced APIs supported chains\n\n`ankr-sdk` supports the following chains at this time:\n\nMainnet\n\n- Ethereum: `\"eth\"`\n- BNB Smart Chain: `\"bsc\"`\n- Polygon: `\"polygon\"`\n- Fantom: `\"fantom\"`\n- Arbitrum: `\"arbitrum\"`\n- Avalanche: `\"avalanche\"`\n- Syscoin NEVM: `\"syscoin\"`\n- Optimism: `\"optimism\"`\n- Polygon zkEVM: `\"polygon_zkevm\"`\n- Rollux: `\"rollux\"`\n- Base: `\"base\"`\n- Flare: `\"flare\"`\n- Gnosis Chain: `\"gnosis\"`\n- Scroll: `\"scroll\"`\n- Linea: `\"linea\"`\n\nTestnet\n\n- Ethereum Goerli: `\"eth_goerli\"`\n- Avalanche Fuji: `\"avalanche_fuji\"`\n- Polygon Mumbai: `\"polygon_mumbai\"`\n- Optimism Testnet: `\"optimism_testnet\"`\n\nAppchain\n\n- META Apes: `\"bas_metaapes\"`\n\nAppchain Testnet\n\n- META Apes Testnet: `\"bas_metaapes_testnet\"`\n\nWhen passing blockchain, you can use one available from `types.py` (preferred) or just a string value.  \n\n## Available methods\n\n`ankr-sdk` supports the following methods:\n\nEarly Access\n\n- [`get_token_price_history`](#gettokenpricehistory--gettokenpricehistoryraw)\n- [`get_account_balance_historical`](#getaccountbalancehistorical--getaccountbalancehistoricalraw)\n- [`get_internal_transactions_by_block_number`](#getinternaltransactionsbyblocknumber--getinternaltransactionsbyblocknumberraw)\n- [`get_internal_transactions_by_parent_hash`](#getinternaltransactionsbyparenthash--getinternaltransactionsbyparenthashraw)\n\nToken API\n\n- [`explain_token_price`](#explaintokenprice--explaintokenpriceraw)\n- [`get_account_balance`](#getaccountbalance--getaccountbalanceraw)\n- [`get_currencies`](#getcurrencies--getcurrenciesraw)\n- [`get_token_holders`](#gettokenholders--gettokenholdersraw)\n- [`get_token_holders_count_history`](#gettokenholderscounthistory--gettokenholderscounthistoryraw)\n- [`get_token_holders_count`](#gettokenholderscount--gettokenholderscountraw)\n- [`get_token_price`](#gettokenprice--gettokenpriceraw)\n- [`get_token_transfers`](#gettokentransfers--gettokentransfersraw)\n\nNFT API\n\n- [`get_nfts`](#getnfts--getnftsraw)\n- [`get_nft_metadata`](#getnftmetadata--getnftmetadataraw)\n- [`get_nft_holders`](#getnftholders--getnftholdersraw)\n- [`get_nft_transfers`](#getnfttransfers--getnfttransfersraw)\n\nQuery API\n\n- [`get_logs`](#getlogs--getlogsraw)\n- [`get_blocks`](#getblocks--getblocksraw)\n- [`get_transaction`](#gettransaction--gettransactionraw)\n- [`get_transactions_by_address`](#gettransactionsbyaddress--gettransactionsbyaddressraw)\n- [`get_blockchain_stats`](#getblockchainstats--getblockchainstatsraw)\n- [`get_interactions`](#getinteractions--getinteractionsraw)\n\n\nNote: some methods are available in *_raw format, allowing to get full reply with syncStatus and control pagination by hands.\n\n### Pagination\n\n- methods with *_raw ending support customized pagination, where you are controlling it, using `pageSize` and `pageToken`\n- other methods support automatic pagination, DON'T use `pageSize` and `pageToken` fields to these methods\n\n---\n\n## Examples\n\n### Early Access API\n\n#### `get_token_price_history` / `get_token_price_history_raw`\n\nGet a list of history of the price for given contract to given timestamp.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTokenPriceHistoryRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_price_history(\n    request=GetTokenPriceHistoryRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='0x50327c6c5a14dcade707abad2e27eb517df87ab5',\n        toTimestamp=1696970653,\n        interval=100,\n        limit=10\n    )\n)\nprint(result)\n```\n\n#### `get_account_balance_historical` / `get_account_balance_historical_raw`\n\nGet the coin and token balances of the wallet at specified block.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetAccountBalanceHistoricalRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_account_balance_historical(\n    request=GetAccountBalanceHistoricalRequest(\n        blockchain=Blockchain.Eth,\n        walletAddress='vitalik.eth',\n        onlyWhitelisted=False,\n        blockHeight=17967813,\n    )\n)\nprint(result)\n```\n\n#### `get_internal_transactions_by_block_number` / `get_internal_transactions_by_block_number_raw`\n\nGet a list of internal transactions in the block.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetInternalTransactionsByBlockNumberRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_internal_transactions_by_block_number(\n    request=GetInternalTransactionsByBlockNumberRequest(\n        blockchain=Blockchain.Eth,\n        blockNumber=10000000,\n        onlyWithValue=True,\n    )\n)\nfor transaction in result:\n    print(transaction)\n```\n\n#### `get_internal_transactions_by_parent_hash` / `get_internal_transactions_by_parent_hash_raw`\n\nGet a list of internal transactions in the transaction.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetInternalTransactionsByParentHashRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_internal_transactions_by_parent_hash(\n    request=GetInternalTransactionsByParentHashRequest(\n        blockchain=Blockchain.Eth,\n        parentTransactionHash='0xa50f8744e65cb76f66f9d54499d5401866a75d93db2e784952f55205afc3acc5',\n        onlyWithValue=True,\n    )\n)\nfor transaction in result:\n    print(transaction)\n```\n\n### Token API\n\n#### `explain_token_price` / `explain_token_price_raw`\n\nGet a list of tokens and pool how price for calculated.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, ExplainTokenPriceRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\npairs, estimates = advancedAPI.explain_token_price(\n    request=ExplainTokenPriceRequest(\n        blockchain=Blockchain.Eth,\n        tokenAddress='0x8290333cef9e6d528dd5618fb97a76f268f3edd4',\n        blockHeight=17463534,\n    )\n)\n\nprint(pairs)\nprint(estimates)\n```\n\n#### `get_account_balance` / `get_account_balance_raw`\n\nGet the coin and token balances of a wallet.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import GetAccountBalanceRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_account_balance(\n    request=GetAccountBalanceRequest(\n        walletAddress=\"0x77A859A53D4de24bBC0CC80dD93Fbe391Df45527\"\n    )\n)\n\nfor balance in result:\n    print(balance)\n```\n\n#### `get_currencies` / `get_currencies_raw`\n\nGet a list of supported currencies for a given blockchain.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetCurrenciesRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_currencies(\n    request=GetCurrenciesRequest(\n        blockchain=Blockchain.Fantom,\n    )\n)\n\nfor currency in result:\n    print(currency)\n```\n\n#### `get_token_holders` / `get_token_holders_raw`\n\nGet the list of token holders for a given contract address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTokenHoldersRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_holders(\n    request=GetTokenHoldersRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='0xdac17f958d2ee523a2206206994597c13d831ec7',\n    )\n)\n\nfor balance in result:\n    print(balance)\n```\n\n#### `get_token_holders_count_history` / `get_token_holders_count_history_raw`\n\nGet historical data about the number of token holders for a given contract address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTokenHoldersCountRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_holders_count_history(\n    request=GetTokenHoldersCountRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='0xdAC17F958D2ee523a2206206994597C13D831ec7',\n    )\n)\n\nfor balance in result:\n    print(balance)\n```\n\n#### `get_token_holders_count` / `get_token_holders_count_raw`\n\nGet current data about the number of token holders for a given contract address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTokenHoldersCountRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_holders_count_history_raw(\n    request=GetTokenHoldersCountRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='0xdAC17F958D2ee523a2206206994597C13D831ec7',\n    )\n)\n\nprint(result)\n```\n\n#### `get_token_price` / `get_token_price_raw`\n\nGet token price by contract.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTokenPriceRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_price(\n    request=GetTokenPriceRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='',\n    )\n)\n\nprint(result)\n```\n\n#### `get_token_transfers` / `get_token_transfers_raw`\n\nGet token transfers of specified address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTransfersRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_token_transfers(\n    request=GetTransfersRequest(\n        blockchain=Blockchain.Eth,\n        address=['0xf16e9b0d03470827a95cdfd0cb8a8a3b46969b91'],\n        fromTimestamp=1674441035,\n        toTimestamp=1674441035,\n        descOrder=True,\n    )\n)\n\nfor transfer in result:\n    print(transfer)\n```\n\n### NFT API\n\n#### `get_nfts` / `get_nfts_raw`\n\nGet data about all the NFTs (collectibles) owned by a wallet.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetNFTsByOwnerRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_nfts(\n    request=GetNFTsByOwnerRequest(\n        blockchain=Blockchain.Eth,\n        walletAddress='0x0E11A192d574b342C51be9e306694C41547185DD',\n    )\n)\n\nfor nft in result:\n    print(nft)\n```\n\n#### `get_nft_metadata` / `get_nft_metadata_raw`\n\nGet NFT's contract metadata.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetNFTMetadataRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nreply = advancedAPI.get_nft_metadata(\n    request=GetNFTMetadataRequest(\n        blockchain=Blockchain.Eth,\n        contractAddress='0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',\n        tokenId='1500',\n        forceFetch=False,\n    )\n)\n\nprint(reply.metadata)\nprint(reply.attributes)\n```\n\n#### `get_nft_holders` / `get_nft_holders_raw`\n\nGet NFT's holders.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetNFTHoldersRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_nft_holders(\n    request=GetNFTHoldersRequest(\n        blockchain=Blockchain.Arbitrum,\n        contractAddress='0xc36442b4a4522e871399cd717abdd847ab11fe88',\n    ),\n    limit=1000\n)\n\nfor holder in result:\n    print(holder)\n```\n\n#### `get_nft_transfers` / `get_nft_transfers_raw`\n\nGet NFT Transfers of specified address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTransfersRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_nft_transfers(\n    request=GetTransfersRequest(\n        blockchain=[Blockchain.Eth, Blockchain.Bsc],\n        address=['0xd8da6bf26964af9d7eed9e03e53415d37aa96045'],\n        fromTimestamp=1672553107,\n        toTimestamp=1672683207,\n    )\n)\n\nfor transfer in result:\n    print(transfer)\n```\n\n### Query API\n\n#### `get_logs` / `get_logs_raw`\n\nGet logs matching the filter.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetLogsRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_logs(\n    request=GetLogsRequest(\n        blockchain=[Blockchain.Eth],\n        fromBlock=1181739,\n        toBlock=1181739,\n        address=[\"0x3589d05a1ec4af9f65b0e5554e645707775ee43c\"],\n        topics=[\n            [],\n            [\"0x000000000000000000000000feb92d30bf01ff9a1901666c5573532bfa07eeec\"],\n        ],\n        decodeLogs=True,\n    ),\n    limit=10\n)\n\nfor log in result:\n    print(log)\n```\n\n#### `get_blocks` / `get_blocks_raw`\n\nQuery data about blocks within a specified range.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetBlocksRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_blocks(\n    request=GetBlocksRequest(\n        blockchain=Blockchain.Eth,\n        fromBlock=14500001,\n        toBlock=14500004,\n        descOrder=True,\n        includeLogs=True,\n        includeTxs=True,\n        decodeLogs=True,\n    )\n)\n\nfor block in result:\n    print(block)\n```\n\n#### `get_transaction` / `get_transaction_raw`\n\nQuery data about transaction by the transaction hash.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import GetTransactionsByHashRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_transaction(\n    request=GetTransactionsByHashRequest(\n        transactionHash='0x82c13aaac6f0b6471afb94a3a64ae89d45baa3608ad397621dbb0d847f51196f',\n        decodeTxData=True\n    )\n)\n\nprint(result)\n```\n\n#### `get_transactions_by_address` / `get_transactions_by_address_raw`\n\nQuery data about transactions of specified address.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetTransactionsByAddressRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_transactions_by_address(\n    request=GetTransactionsByAddressRequest(\n        blockchain=Blockchain.Bsc,\n        fromBlock=23593283,\n        toBlock=23593283,\n        address=[\n            \"0x97242e3315c7ece760dc7f83a7dd8af6659f8c4c\"\n        ],\n        descOrder=True,\n    )\n)\n\nfor transaction in result:\n    print(transaction)\n```\n\n#### `get_blockchain_stats` / `get_blockchain_stats_raw`\n\nReturns blockchain stats (num of txs, etc.).\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import Blockchain, GetBlockchainStatsRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_blockchain_stats(\n    request=GetBlockchainStatsRequest(\n        blockchain=Blockchain.Bsc,\n    )\n)\n\nfor stat in result:\n    print(stat)\n```\n\n#### `get_interactions` / `get_interactions_raw`\n\nReturns on which chain address was interacting.\n\n```python3\nfrom ankr import AnkrAdvancedAPI\nfrom ankr.types import GetInteractionsRequest\n\nadvancedAPI = AnkrAdvancedAPI(\"YOUR-TOKEN\")\n\nresult = advancedAPI.get_interactions(\n    request=GetInteractionsRequest(\n        address='0xF977814e90dA44bFA03b6295A0616a897441aceC',\n    )\n)\n\nfor blockchain in result:\n    print(blockchain)\n```\n\n\n\n### About API keys\n\nAnkr is offering _free_ access to Advanced API, however you have to register on Ankr platform to access it.\n\nGet your individual API Key here https://www.ankr.com/rpc/advanced-api.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Compact Python library for interacting with Ankr's Advanced APIs.",
    "version": "1.0.1",
    "project_urls": {
        "Homepage": "https://ankr.com/",
        "Repository": "https://github.com/Ankr-network/ankr-python-sdk"
    },
    "split_keywords": [
        "ankr",
        " sdk",
        " blockchain",
        " nft"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8a91baa0e2ceb5892cc09404ed485d757ce9d3a03d9458c20b99fb4fad5a12f7",
                "md5": "1efb47992c1ee42cbf9c22bf8e963a29",
                "sha256": "7bcf4f0eec493fe6b2da57e09bce2236dca830864c5bed26c8291b22517983c8"
            },
            "downloads": -1,
            "filename": "ankr_sdk-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1efb47992c1ee42cbf9c22bf8e963a29",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 18448,
            "upload_time": "2024-03-29T13:48:22",
            "upload_time_iso_8601": "2024-03-29T13:48:22.574543Z",
            "url": "https://files.pythonhosted.org/packages/8a/91/baa0e2ceb5892cc09404ed485d757ce9d3a03d9458c20b99fb4fad5a12f7/ankr_sdk-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a56d281d421e08f1ed2f22e7b2a7e21cd7e3e58478a9bce5f0f1cf222407ed5",
                "md5": "0eb6892cadd0bc2aee9b9543e550b6b9",
                "sha256": "e7d1704e8596da31089d8f866df9c83ed2f7b3e28a906c237643c8524766351e"
            },
            "downloads": -1,
            "filename": "ankr_sdk-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0eb6892cadd0bc2aee9b9543e550b6b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.8.1",
            "size": 19710,
            "upload_time": "2024-03-29T13:48:24",
            "upload_time_iso_8601": "2024-03-29T13:48:24.238063Z",
            "url": "https://files.pythonhosted.org/packages/9a/56/d281d421e08f1ed2f22e7b2a7e21cd7e3e58478a9bce5f0f1cf222407ed5/ankr_sdk-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 13:48:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ankr-network",
    "github_project": "ankr-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ankr-sdk"
}
        
Elapsed time: 0.23854s