Skip to content

  Spin up a managed Avalanche node cluster in minutes! Learn More.

The Sync Blog

Updates and insights from the Bloq team

« Blog Home

How-To: Retrieve Balances from Ethereum and Ethereum Classic Accounts

This week, we announced the general availability of our Bloq Connect API service for Ethereum and Ethereum Classic, the result of our partnership with Ethereum Classic Labs

To get you started, we wanted to deliver a quick guide and start with the simplest of operations: querying addresses to retrieve a balance, similar to our earlier Bitcoin lesson.   

Through the Bloq Connect service, users can access a number of API calls to interact with Ethereum and Ethereum Classic, among other chains. Because ETH and ETC use different methods for record keeping, transactions, and so on than Bitcoin and its cousins (see previous article on this topic), a separate toolkit is required specifically to interact with these chains.

To execute calls to Ethereum and Ethereum Classic through Bloq Connect, users must interact through the ETH/ETC JSON-RPC interfaces. Below, we’ll outline the steps required to query the blockchain to get the ether balance associated with an account.

JSON-RPC: eth_getBalance

By calling the JSON-RPC eth_getBalance method directly from the terminal, users can supply an Ethereum account address to receive its corresponding ether balance.

In order to execute Bloq Connect API calls for Ethereum and Ethereum Classic, a project id is required. You can create a project id through the Bloq console.

Alongside the project id, you’ll need an ETH address to query. For this example, we’ll use the address responsible for mining an early Ethereum block, 0x05a56E2D52c817161883f50c441c3228CFe54d9f:

Paste your project id into the URL where prompted. When executed in the command line, the above call returns the ETH balance in wei. Wei is the smallest unit of ETH, with one wei corresponding to 1*10-18 ETH.

There is an additional parameter accompanying the queried address: “latest.” With eth_getBalance, you can provide an Ethereum block number to grab the account balance at that block. Alternatively, you can use “earliest” to get the balance at genesis block, “pending” to include all pending transactions, and “latest” for the most up-to-date confirmed balance.

Ethereum JSON-RPC calls generally use the same syntax. The data (-d) field communicates the method called, parameters, protocol version, and method id. The header (-H) asserts that the data supplied is communicated to the API URL in the JSON format. The HTTP method (POST or GET, typically) is set with -X.

The above code will produce an ether balance in hexadecimal format. Please see the technical reference to learn how to append Python code to the API call to automatically convert the output to decimal.

Other methods can similarly be used to get additional account information, such as transaction receipts. This list of all of the ETH / ETC calls accessible via Bloq Connect has more.

Ethereum Classic

In its essence, Ethereum Classic offers a mirror of the Ethereum toolkit. To interact with the ETC blockchain, change eth in the API url to etc. The method names remain unchanged. The previous command, when converted to Ethereum Classic, reads as follows:

When executed in the terminal, the command should return “0x0” (zero). The address supplied was a pre-fork Ethereum address, so it did hold ETC once-upon-a-time, but its entire balance was moved elsewhere several years ago at block 998791.

The transaction hash for the withdrawal was 0xeee4e322769f5929c626d7ed31f8b29cad4f62bd14964bf289064e67763f3bdc. You can see the transaction by its hash with eth_getTransactionByHash:

Your output should show the above address as the sender and a transaction value of 0x64bdc4b1a721d2c40. This translates to 116146791066933996608 wei (116.1467 ETC).

Once you’ve familiarized yourself with the above methods, explore the other Ethereum JSON-RPC calls to get an idea of the breadth of information that is accessible and how you may apply that to more advanced applications.

Join the Bloq newsletter for the latest updates

This field is for validation purposes and should be left unchanged.