Search documentation

Connecting to an RPC Endpoint

To use AnyBlock as an RPC node provider, you need to connect to one of your personal endpoint URLs containing your API key.

See also: Setting up an Anyblock RPC Node API access with Python and web3.py.

Step 1. Selecting an Endpoint URL

In the RPC tab of your Anyblock account, you can find the list of the ETH and BTC endpoints available to you. Each URL contains a reference to a network and is expanded by your personal API key found in the API Keys tab.

For example, here is the URL structure for working with the Ethereum Mainnet:

https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc/YOUR-API-KEY/
And here is how an actual URL may look like:
https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc/126a031b-4a93-473f-b12d-8ecb968797c8/

Step 2. Connecting to the Endpoint

To establish a connection to the selected endpoint, add the following steps to your application:

  1. Import the blockchain library you use
  2. Set a provider with the endpoint URL as a parameter

Examples

In the sections below, there are code samples showing how to establish and test the connection in different blockchain libraries.

The connection is tested by logging the current block number. If you run your application, you will get an output like this:

Current block number:  13284357

ethers.js

Connecting to the endpoint:

//import the library
const ethers = require("ethers"); 

// set the node URL
const url = "https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc/YOUR-API-KEY/";
 
// set the provider
const provider = new ethers.providers.JsonRpcProvider(url);
Testing the connection:
// display the current block number
provider.getBlockNumber().then((result) => {
  console.log("Current block number: " + result);
});

web3.js

Connecting to the endpoint:

// import the library
const Web3 = require("web3");
 
// set the node URL
const url = "https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc/YOUR-API-KEY/";
 
// set the provider
const provider = new Web3(new Web3.providers.HttpProvider(url));
Testing the connection:
// display the current block number
provider.eth.getBlockNumber().then((result) => {
  console.log("Current block number: " + result);
});

web3.py

Connecting to the endpoint:

# import the library
from web3 import Web3
 
# set the node URL
url = "https://api.anyblock.tools/ethereum/ethereum/mainnet/rpc/YOUR-API-KEY/"
 
# set the provider
provider = Web3(Web3.HTTPProvider(url))
Testing the connection:
# get the current block number
blockNumber = provider.eth.block_number
 
# display the current block number
print("Current block number: ", blockNumber)

Interested or questions?

 

Sascha Göbel
(Co-Founder & Chief Technology Officer)
sascha@anyblockanalytics.com
+49 6131 3272372

    

Pin It on Pinterest