curl
The Client Uniform Resource Locator (curl) command line tool sends API requests via URLs and returns responses.
Requests to Infura APIs commonly use curl.
We recommend the resource Everything curl.

Install curl

Your operating system may include curl, or you may need to download and install it.
Check the "Get curl" chapter of Everything curl for the best way to install curl for your operating system.

curl commands

Many Infura requests take the form:
1
curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}'
Copied!
The code snippet above is an API call to Infura's Ethereum mainnet endpoint.
It requests the latest block number using the method eth_blockNumber.

curl analysis

Let's step through each line of the code snippet to understand what's happening.
The first line uses the curl command to send a request to the URL https://mainnet.infura.io/v3/YOUR-PROJECT-ID.

curl command

1
curl https://mainnet.infura.io/v3/PROJECT-ID \
Copied!
Replace PROJECT-ID with a specific Ethereum project id.

-X flag

The -X flag specifies a common HTTP method.
1
-X POST \
Copied!

-H flag

The -H or --header flag specifies header information.
The example specifies the Content-Type to be application/json which means the requested resource is a JavaScript Object Notation (JSON) object.
1
-H "Content-Type: application/json" \
Copied!

-d flag

The -d or --data flag specifies more information sent along with the curl request.
In the example, the data object is a list of key value pairs in JSON format. This follows the JSON RPC 2.0 specification which requires the four specific keys seen here.
The method , params , and id values are modifiable.
The jsonrpc value is required by the specification.
1
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}'
Copied!

Running curl

Enter curl code in a terminal window, or a command line tool from your computer's operating system and click return.

Output

curl returns a response object if the request is successful.
1
{"jsonrpc":"2.0","id":3,"result":"0xe0a763"}
Copied!
For more information, Everything curl has a useful cheat sheet on curl and HTTP.