Infura API
mainnet.infura.io · Developer Tools
Ethereum and IPFS node access without running your own node. JSON-RPC API for sending transactions, reading contract state, and querying blockchain data. Free: 100,000 requests/day.
Authentication
API Key
Free API key (Project ID) at infura.io. Included in the endpoint URL: mainnet.infura.io/v3/YOUR_PROJECT_ID.
Sample Requests
POST
Get latest block
Get the current Ethereum block number.
https://mainnet.infura.io/v3/YOUR_PROJECT_ID
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Content-Type | application/json |
Request Body — data you're sending
{
"id": 1,
"method": "eth_blockNumber",
"params": [],
"jsonrpc": "2.0"
}
curl -X POST "https://mainnet.infura.io/v3/YOUR_PROJECT_ID" \
-H "Content-Type: application/json" \
-H "Content-Type: application/json" \
-d '{"id":1,"method":"eth_blockNumber","params":[],"jsonrpc":"2.0"}'import requests
headers = {
"Content-Type": "application/json"
}
data = {
"id": 1,
"method": "eth_blockNumber",
"params": [],
"jsonrpc": "2.0"
}
response = requests.post(
"https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
headers=headers,
json=data,
)
print(response.json())const url = 'https://mainnet.infura.io/v3/YOUR_PROJECT_ID';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"id": 1,
"method": "eth_blockNumber",
"params": [],
"jsonrpc": "2.0"
}),
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"bytes"
"encoding/json"
)
func main() {
targetURL := "https://mainnet.infura.io/v3/YOUR_PROJECT_ID"
jsonData, _ := json.Marshal({"id":1,"method":"eth_blockNumber","params":[],"jsonrpc":"2.0"})
req, _ := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://mainnet.infura.io/v3/YOUR_PROJECT_ID")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Content-Type"] = "application/json"
req.body = "{\"id\":1,\"method\":\"eth_blockNumber\",\"params\":[],\"jsonrpc\":\"2.0\"}"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://mainnet.infura.io/v3/YOUR_PROJECT_ID";
$opts = ["http" => [
"method" => "POST",
"header" => implode("\r\n", [
"Content-Type: application/json",
"Content-Type: application/json"
]),
"content" => json_encode({"id":1,"method":"eth_blockNumber","params":[],"jsonrpc":"2.0"}),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
POST
Get ETH balance
Get ETH balance via JSON-RPC.
https://mainnet.infura.io/v3/YOUR_PROJECT_ID
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Content-Type | application/json |
Request Body — data you're sending
{
"id": 1,
"method": "eth_getBalance",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"latest"
],
"jsonrpc": "2.0"
}
curl -X POST "https://mainnet.infura.io/v3/YOUR_PROJECT_ID" \
-H "Content-Type: application/json" \
-H "Content-Type: application/json" \
-d '{"id":1,"method":"eth_getBalance","params":["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","latest"],"jsonrpc":"2.0"}'import requests
headers = {
"Content-Type": "application/json"
}
data = {
"id": 1,
"method": "eth_getBalance",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"latest"
],
"jsonrpc": "2.0"
}
response = requests.post(
"https://mainnet.infura.io/v3/YOUR_PROJECT_ID",
headers=headers,
json=data,
)
print(response.json())const url = 'https://mainnet.infura.io/v3/YOUR_PROJECT_ID';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"id": 1,
"method": "eth_getBalance",
"params": [
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"latest"
],
"jsonrpc": "2.0"
}),
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"bytes"
"encoding/json"
)
func main() {
targetURL := "https://mainnet.infura.io/v3/YOUR_PROJECT_ID"
jsonData, _ := json.Marshal({"id":1,"method":"eth_getBalance","params":["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","latest"],"jsonrpc":"2.0"})
req, _ := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://mainnet.infura.io/v3/YOUR_PROJECT_ID")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Content-Type"] = "application/json"
req.body = "{\"id\":1,\"method\":\"eth_getBalance\",\"params\":[\"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045\",\"latest\"],\"jsonrpc\":\"2.0\"}"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://mainnet.infura.io/v3/YOUR_PROJECT_ID";
$opts = ["http" => [
"method" => "POST",
"header" => implode("\r\n", [
"Content-Type: application/json",
"Content-Type: application/json"
]),
"content" => json_encode({"id":1,"method":"eth_getBalance","params":["0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045","latest"],"jsonrpc":"2.0"}),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Create a free account at infura.io
- Create a new API key (Project ID)
- Endpoint: https://mainnet.infura.io/v3/YOUR_PROJECT_ID
- POST with JSON-RPC body: {"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}
- Balance is in hex Wei — divide by 1e18 for ETH