API Reference
DocumentationLog In

Ethereum API quickstart: Get the latest block on Ethereum

This quickstart will get you up and running with your first call to the Ethereum API, using Coinbase Node's Instant API Access.

In this tutorial, you will get the latest block on the Ethereum blockchain.

Prerequisites

⚠️

If you're using a Windows machine as your dev environment, you can run through this tutorial as-written by using Windows Subsystem for Linux

Create a project and get API keys

To get started using the Coinbase Node Ethereum API, sign in to your Coinbase Cloud account:

Sign in to Coinbase Cloud Console screenSign in to Coinbase Cloud Console screen

Create project

After you sign in you'll be prompted to set up your first project. A project provides access to a shared node where you can make calls to the Ethereum API. See our guide to the Ethereum API for more info.

Select the free tier plan and enter a name for your project.

Create a project screenCreate a project screen

Get API keys

After creating a project, you will receive the following API access credentials:

  • API Access Token Username (e.g. username)

  • API Access Token Password (e.g. password)

    API token modalAPI token modal

Copy and save these API access credentials to a secure location. You will need them later in order to make API requests.

⚠️

You can return to the project dashboard to retrieve your endpoint and username, however your password is not saved.

If you lose your project password, you will need to create a new project.

Once your project is created, you can visit the dashboard to view other information, such as the endpoint (https://mainnet.ethereum.coinbasecloud.net).

Empty projectEmpty project

Make a request

Open your terminal and run the following command, replacing <username>, and <password> with the values you copied from the Console.

curl https://mainnet.ethereum.coinbasecloud.net/ \
  -u <username>:<password> \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
  "method": "eth_blockNumber",
  "params": [],
  "id": 1,
  "jsonrpc": "2.0"
}'

Get response

Calling the eth_blockNumber API returns a JSON response with a property result. result contains the number of the most recent block on the Ethereum blockchain, formatted in hexadecimal.

The response will have this format, with a different result data.

{"jsonrpc":"2.0","id":1,"result":"0xe83f20"}

To get the block number in a more readable decimal, or base 10, format, you can convert it with any hex to decimal converter.

Convert response to decimal (optional)

To easily get the block number in decimal format, you can use the command line utility jq, for processing JSON, to get the result value from the returned JSON and printf to convert the hexadecimal data to decimal.

Open your terminal and run the following command

 curl https://mainnet.ethereum.coinbasecloud.net/ \
  -u <username>:<password> \
  -X POST \
  -H 'Content-Type: application/json' \
  -d '{
  "method": "eth_blockNumber",
  "params": [],
  "id": 1,
  "jsonrpc": "2.0"
}' | jq '.result' | xargs printf "%d\n"

Now your output should be the block number in decimal format:

15221255

You did it! You've made your first call to the Ethereum API.

Next, check out the Ethereum API docs to see what else you can do with Coinbase Node.