Anyblock is now proudly part of Blockdaemon - read the announcement in our blog
Dec 15, 2021

Anyblock Multi-Chain REST API for RPC & Data

by

Icon article header
Visual Hand Node
Anyblock REST API endpoints for RPC & data are a fast and reliable solution, which is available for more than 20 blockchains and does not require running your own node. You can view the list and description of all our endpoints in the Anyblock REST API docs.

In this article, you will find general information on Anyblock API and examples showing how to interact with it.

Public vs Registered User Calls

Anyblock provides a number of public endpoints that do not require registration. For example, anyone can get the estimated gas fees in a given network.

However, most endpoints require an account. To access RPC, Elasticsearch, alerting, and many other endpoints, you need to register here and get your API key. See also: How to get started with Anyblock?

In Anyblock REST API docs, the lock icon to the right of an endpoint indicates that it requires registration. The endpoints without the icon can be used freely.

Public Api Endpoint
Image: an Anyblock API endpoint available for non-registered users. Click to enlarge.
registered user api endpoint
Image: an Anyblock API endpoint available only for registered users. Click to enlarge.

URL Structure

The base URL for accessing Anyblock API is the following:
https://api.anyblock.tools/

For most of the endpoints we provide, you should also specify the technology, blockchain, and network:

/{technology}/{blockchain}/{network}/

Each network is a part of a certain blockchain platform, which, in turn, is based on a certain technology, such as Ethereum or Bitcoin. For example, POA is an Ethereum-based platform, so for all its networks (Core, xDai, Sokol) you should specify ethereumas the technology, poaas the blockchain, and core/xdai/sokolas the network:

https://api.anyblock.tools/ethereum/poa/xdai/

Here is the URL for interacting with Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/

(However, this network is default, so the /ethereum/ethereum/mainnet/part can be omitted.)

Examples

 

Public

The public endpoints provided by Anyblock do not require Anyblock API key, so even unregistered users can work with them.
You can retrieve the available networks, technologies, and blockchains as well as the main information on them:

GET /networks
GET /technologies
GET /{technology}/blockchains
GET /{technology}/{blockchain}/networks
GET /{technology}/{blockchain}/{network}/latest-blocktime
GET /{technology}/{blockchain}/{network}/icon
GET /{technology}/{blockchain}/{network}/icon/token/{address}
GET /{technology}/{blockchain}/{network}/latest-transactioncount-per-block
GET /{technology}/{blockchain}/{network}/gasprice
GET /{technology}/{blockchain}/{network}/block-height
GET /{technology}/{blockchain}/{network}/{address}/gasprice
GET /{technology}/{blockchain}/{network}/{address}/gasusage

See also our multi-chain Network Metrics dashboard, which visualizes the information that is available via some of these endpoints.
For example, this is how you get the estimated gas fees and other gas metrics in a given network:

GET /{technology}/{blockchain}/{network}/gasprice

Here is a sample request and the output for Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/gasprice
{
    "health": true,
    "blockNumber": 13556603,
    "blockTime": 14.28643216080402,
    "slow": 102.41,
    "standard": 113.923499284,
    "fast": 136.074253706,
    "instant": 173.935867462,
    "latestBlockBaseFee": 111.176308673,
    "latestBlockMinFee": 111.176308673,
    "eip1559": {
        "slow": {
            "probability": "30%",
            "priorityFee": 0,
            "maxFee": 222.352617346
        },
        "standard": {
            "probability": "60%",
            "priorityFee": 1,
            "maxFee": 223.352617346
        },
        "fast": {
            "probability": "90%",
            "priorityFee": 1.5,
            "maxFee": 223.852617346
        },
        "faster": {
            "probability": "96%",
            "priorityFee": 2,
             "maxFee": 224.352617346
        },
        "instant": {
            "probability": "99%",
            "priorityFee": 3,
            "maxFee": 225.352617346
        }
    }
}

The calculation method and the output of this endpoint depend on whether a given network supports Ethereum’s EIP-1559 update. To learn more, see the Gas Endpoints article in our documentation.

RPC

You can use our endpoint to execute JSON-RPC calls against blockchain nodes:

POST /{technology}/{blockchain}/{network}/rpc

Anyblock JSON-RPC Node API is a fast and reliable solution, load-balanced with multiple nodes and fully compatible with standard Ethereum & Bitcoin RPC. There is no need to run your own node – you can access the data enriched and indexed by Anyblock, including archive data.
To learn more, visit the section Connecting to an RPC Endpoint in our documentation and the tutorial Setting up an Anyblock RPC Node API access with Python.
You can find the list of supported networks in the RPC tab of your Anyblock account. Also, please keep in mind that a JSON-RPC call requires adding a request object. For example, In Postman you should add it in the Body tab of your request.
Here is a request (with a body) for getting the balance of an address in Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc
{
   	"method":"eth_getBalance",
   	"params": ["0xcCd9F664E4E927976C7bF9FCC7f1B0C71c218364", "latest"]
}

Elasticsearch

Elasticsearch is a search and analytics engine used to retrieve unstructured data from distributed nodes. Anyblock does not limit Elasticsearch query formats to a finite set of endpoints, instead of providing a set of generic endpoints for any queries using different APIs of Elastic:
URI Search:GET ​/{technology}​/{blockchain}​/{network}​/<strong>es​/{type}​/search</strong>

Request Body Search:POST /{technology}/{blockchain}/{network}/es/{type}/search

Count:GET /{technology}/{blockchain}/{network}/es/{type}/count

Count:POST /{technology}/{blockchain}/{network}/es/{type}/count

Scroll:POST /{technology}/{blockchain}/{network}/es/search/scroll

In addition, you can ping the Elastic cluster to check whether it is alive:

GET /{technology}/{blockchain}/{network}/es/ping

To dive deeper, read our Elasticsearch documentation – in particular, explore the Elasticsearch data structure.
Also, take a look at a sample URI Search query that outputs the latest block in Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/es/block/0xf44f60a66257d1c6c8afd2a64aaeb306d9c471d5d38b6dc277811455192ecee1/
{
	"_index": "0014-ethereum-ethereum-mainnet-block",
	"_type": "_doc",
	"_id": "0xf44f60a66257d1c6c8afd2a64aaeb306d9c471d5d38b6dc277811455192ecee1",
	"_version": 1,
	"_seq_no": 1798941,
	"_primary_term": 1,
	"found": true,
	"_source": {
    	"author": "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
    	"difficulty": {
            "raw": "3334775583391707",
            "padded": "0x000000000000000000000000000000000000000000000000000bd8f5f20dbfdb"
    	},
    	"extraData": "0x6e616e6f706f6f6c2e6f7267",
    	"gasLimit": {
            "raw": "8000029",
            "num": 8000029
    	},
    	"gasUsed": {
            "raw": "6957348",
            "num": 6957348
    	},
    	"hash": "0xf44f60a66257d1c6c8afd2a64aaeb306d9c471d5d38b6dc277811455192ecee1",
    	"logsBloom": "0x100650e6104a143440c22500080008104100a0684032300060200522022883088902081042c021202c20d442b140052002a80000098980d0300840221436100140280045002221b248d06a5840209480028200221960808042112108422810000160902203202108c20002380020a8208c501a10acc64460008181100440400429394a1041454004c201090c01402c294042082c09802010608200180612e200232880322240ea4c020070f000a4704100480041218088841203c8900220222144201406118820000804400242801001040800b683480a4500418000c04020a00810202490a024818a02048000402026000010000051200d61b7000240a45001",
    	"miner": "0x52bc44d5378309EE2abF1539BF71dE1b7d7bE3b5",
    	"mixHash": "0xe02e54148fab5709396dcf6d1f49cef5ca6ae515df76a0f7f173dd95ac38ca48",
    	"nonce": "0x15fe52f8166174ac",
    	"number": {
            "raw": "5276002",
            "num": 5276002
    	},
    	"parentHash": "0x65008e9fc21ff83b5fac96a1947a6af26cc2d635ae7200bdcda22c078721c018",
    	"receiptsRoot": "0x19765d7151cddf60be724103ef77e0e1f029852cc9be442fcb8f731006634626",
    	"sha3Uncles": "0xf9c214445a2d7605888b1fa42ba1eca2f2f2c1d723c581112fd2ff14fc2998b2",
    	"size": {
            "raw": "23947",
            "num": 23947
    	},
    	"stateRoot": "0x862d3f78daaeb39d8341fb0aed2c722f4af62ee9e4b9911463c65f2487470a44",
    	"timestamp": 1521357127,
    	"totalDifficulty": {
            "raw": "3111969273457976007086",
            "padded": "0x0000000000000000000000000000000000000000000000a8b33fce4a491bd9ae"
    	},
    	"transactionsRoot": "0x1f2373606703f06df3bf3365d501bcab77f3f39c6a612424e3bdea2632c7018d",
    	"uncles": [
            "0x12d55c79b0b98bfcde920db201e4cc4360073506a562a5063eba7788eb5d36a7"
    	],
    	"sealFields": [
            "0xa0e02e54148fab5709396dcf6d1f49cef5ca6ae515df76a0f7f173dd95ac38ca48",
            "0x8815fe52f8166174ac"
    	]
	}
}

Alerting

Via Anyblock API, you can add, edit, delete, or retrieve alerts as well as the schema for them:

GET /{technology}/{blockchain}/{network}/alerting/schema
GET /{technology}/{blockchain}/{network}/alerting/rules
POST /{technology}/{blockchain}/{network}/alerting/rules
PUT /{technology}/{blockchain}/{network}/alerting/rules/{alertId}
DELETE /{technology}/{blockchain}/{network}/alerting/rules/{alertId}

Our alerting feature (available only to paying users) is capable of monitoring and alerting mostly all of the information that a blockchain emits. For a detailed description, see the Alerting & Push Notifications section of our documentation. Please keep in mind that you can also work with alerts via backend, in the Alerting tab or your Anyblock profile.

Public Api Endpoint
Image: an alert in the Alerting tab of the Anyblock profile page. Click to enlarge.
Alerting via backend 02
Image: alerting settings in the Alerting tab of the Anyblock profile page. Click to enlarge.
Alerting rules are defined in JSON – you can get the schema via the GET /alerting/schema endpoint or view the JSON Schema section in docs. In Postman, for example, you should add the rule in the Body tab of your request.
Alerting via Postman
Image: an alerting rule in the Body tab of a Postman request. Click to enlarge.
Here is a request (with a body) for monitoring the balance of an address in Ethereum Mainnet:
POST https://api.anyblock.tools/ethereum/ethereum/mainnet/alerting/rules
{
    "name": "GasBalance",
    "technology": "ethereum",
    "blockchain": "ethereum",
    "network": "mainnet",
    "maxConfirmationCount": 5,
    "state": "enabled",
    "config": {
        "targetType": "Balance",
        "targetMap": [
            {
                "name": "address",
                "value": "0xAddress",
                "operator": "Equals (ignore case)"
            }
        ],
        "alerts": [
            {
                "type":"Email",
                "payload": [
                    {
                        "fieldName":"transactionHash",
                        "fieldType":"Field"
                    }
                ],
                "parameters": {
                    "recipients": [
                        "YOUR-EMAIL@ADDRESS.COM"
                    ]
                }
            }
        ]
    }
}

To use this code, you should edit the following parts:

  • targetMap>address>value – the address of the contract to monitor
  • targetMap>address>value – the Wei balance notated in hex
  • alerts>parameters>recipients – your email address

Contract/Token

Our endpoints allow retrieving or submitting the contract/token meta information for a given address:

GET /{technology}/{blockchain}/{network}/contract/{address}/meta
POST /{technology}/{blockchain}/{network}/contract/{address}/meta
GET /{technology}/{blockchain}/{network}/token/{address}/meta
POST /{technology}/{blockchain/{network}/token/{address}/meta

The response of these endpoints is refined from longtail on-chain data. To learn more, see our Method Signature Decoding article.
Note: if you don’t see events for your smart contract, you can send us the ABI or as a paying customer you can upload it directly. To learn more, see this FAQ.

Uploading ABI
Image: the form for uploading ABI in the Enrichments tab of the Anyblock profile page. Click to enlarge.
Here is a sample request retrieving the meta information for an Ethereum Mainnet contract with the address 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359:
https://api.anyblock.tools/ethereum/ethereum/contract/0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359/meta
{
    "address": "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359",
    "abi": "...",
    "name": "DSToken",
    "runs": {
        "raw": "200",
        "num": 200
    },
    "source": "...",
    "compiler": "v0.4.19+commit.c4cbbb05",
   	"library": "",
    "optimizations": true,
    "proxy": false,
    "implementation": "",
    "license": "",
    "createdAt": 1513566638,
    "updatedAt": 1635124702,
    "constructorArgs": [
        {
            "value.hex": "0x4441490000000000000000000000000000000000000000000000000000000000",
            "name": "symbol_",
            "value.type": "bytes32",
            "pos": 0
        }
    ],
    "probability": 1
}

For your convenience, Anyblock automatically detects the type of token (ERC20 or ERC721) and displays the details accordingly. For example, here is a request retrieving the meta information for an ERC20 Ethereum Mainnet token with the address 0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359:

https://api.anyblock.tools/ethereum/ethereum/mainnet/token/0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359/meta
{
    "address": "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359",
    "name": "Sai Stablecoin v1.0",
    "symbol": "SAI",
    "type": "ERC20",
    "totalSupply": {
        "raw": "3209495827969720668477720"
    },
    "links": [
        ...
    ],
    "decimals": 18,
    "probability": 1,
    "updatedAt": 1635124703,
    "createdAt": 1513566638
}

The following request retrieves the meta information for an ERC721 Ethereum Mainnet token with the address 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d:

https://api.anyblock.tools/ethereum/ethereum/mainnet/token/0x06012c8cf97BEaD5deAe237070F9587f8E7A266d /meta
{
    "address": "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d",
    "name": "CryptoKitties",
    "symbol": "CK",
    "type": "ERC721",
    "totalSupply": {
        "raw": "2008528",
        "num": 2008528
    },
    "links": [
        ...
    ],
    "decimals": 0,
    "probability": 1,
    "updatedAt": 1633349127,
    "createdAt": 1511415679
}

Token and Coin Balance

Anyblock API enables you to retrieve the current and historical balances of tokens and native coins:

GET /{technology}/{blockchain}/{network}/token/{tokenAddress}/balance
GET /{technology}/{blockchain}/{network}/token/{tokenAddress}/balance/historical
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/tokenbalance
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/tokenbalance/historical
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/tokenbalance/{tokenAddress}
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/tokenbalance/{tokenAddress}/historical
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/coinbalance
GET /{technology}/{blockchain}/{network}/wallet/{walletAddress}/coinbalance/historical

These endpoints are described in our documentation – see the Token & Coin Balance Endpoints section. To learn about how they can be used in real practice, see the Use Cases Token Balances article. Also, note that the information on token and coin balances is available in our Block Explorer tool if you enter or select a token or wallet address.

You can get:

  • the token balances of the top 500 accounts holding a given token
  • token/coin balances of a given wallet
  • the balance of a given token in a given wallet

For example, here is how to retrieve the current balances of the top 500 accounts holding a given token address in Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/token/0xBA11D00c5f74255f56a5E366F4F77f5A186d7f55/balance
[
    {
        "id": "0x3035de3113e6c0bc8f13b499a22ec2b4b2cbfe286b432abc09a2d335b9c71436",
        "account": "0x7a62a7DcF64e1eB94E374ec187AD14BA6e595062",
        "block_hash": "0xf3f1f0e8bd5ef11560f8351a5115f8a098153acc06d4b51fe1ac61b3548055a6",
        "block_number": "11635184",
        "balance": "62387284500000000000000000",
        "balance_scaled": "62387284.5",
        "timestamp": 1610388892
    },
    ...
]

To retrieve all historical token balances of a given wallet address between two given timestamps, use the request as below. In addition, it outputs the meta information of the tokens.

https://api.anyblock.tools/ethereum/ethereum/mainnet/wallet/0x4b732af53A79636902964012F6655d32ADe81E7F/tokenbalance/historical/?fromTimestamp=1619827200&toTimestamp=1619902800
[
    {
        "id": "0x2a4d11c719c23ddb4f30c0d1cad1af0a5b7c87e7b14a8f0a3ad632a133af9ca2",
        "token": {
        	"symbol": "UNI-V2",
        	"address": "0x37b4Cae8d2581E81140e2e172d4D7Aed3A675bc7",
        	"name": "Uniswap V2"
        },
        "block_hash": "0x13f12defbaf1fe683ed6367e83aa3f7f16912248eb7747a029dfe2be2f44c90a",
        "block_number": "12036452",
        "balance": "0",
        "balance_scaled": "0",
        "timestamp": 1619827200
    },
    ...
]

Method

By using method signature decoding, Anyblock matched most Ethereum transactions to corresponding calls and translated most logs to human-readable events. It allows you to retrieve methods that match a given name or signature hash:

GET /{technology}/{blockchain}/{network}/signature/{signatureId}

In other words, this API endpoint takes a method identifier as an input and returns the information on the corresponding methods in any of the networks supported by Anyblock. The following identifiers can be used:

  • 32-byte hash
  • 4-byte hash
  • method name

Here is a sample request for retrieving the Ethereum Mainnet methods matching the 32-byte hash

0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef

:

https://api.anyblock.tools/ethereum/ethereum/signature/0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
[
    {
        "params": [
            {
                "position": 0,
                "name": "",
                "indexed": false,
                "type": "address"
            },
            {
                "position": 1,
                "name": "",
                "indexed": false,
                "type": "address"
            },
            {
                "position": 2,
                "name": "",
                "indexed": false,
                "type": "uint256"
            }
        ],
        "name": "Transfer",
        "signatureHash": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
        "indexedParamsCount": 0,
        "createdAt": 1628704689,
        "updatedAt": 1634912092,
        "probability": 1
    },
    {...}
]

Recap

From this article you learned the basics about Anyblock endpoints and how to use some of them to perform various tasks: execute JSON-RPC calls, use Elasticsearch, configure alerts, etc. There are, however, even more things you can do.
Consider these further reading suggestions:

Interested or questions?

 

Freddy Zwanzger
(Co-Founder & Chief Data Officer)
freddy@anyblockanalytics.com
+49 6131 3272372

    

Looking to create an Anyblock account?

Takes seconds and it's free!

Recent Posts

November Twitter Summary

November Twitter Summary

Hey there, developers! Anyblock Twitter Summary for the month of November is here.  Read it here or check out our Twitter account.Enjoy it!  Or just follow us directly if it's easier for you. Happy tweet-reading! :)🤔 Most people believe they need to operate a...

This is the beginning of a new chapter…

This is the beginning of a new chapter…

We are super excited to announce that Anyblock Analytics GmbH will be spearheading the expansion of Blockdaemon Inc. in Germany! The corresponding contracts have been signed last week and closing is expected shortly as well.

Ein neues Kapitel wird aufgeschlagen…

Ein neues Kapitel wird aufgeschlagen…

Wir freuen uns sehr, dass die Anyblock Analytics GmbH die Expansion der Blockdaemon Inc. in Deutschland anführen wird! Dazu wurden letzte Woche die entsprechenden Verträge unterzeichnet und mit dem endgültigen Vollzug ist kurzfristig zu rechnen.

Pin It on Pinterest