JSON-RPC Interface 🌐
Interacting with Juno requires sending requests to specific JSON-RPC API methods. Juno supports all of Starknet's Node API Endpoints over HTTP and WebSocket.
Enable the JSON-RPC server
To enable the JSON-RPC interface, use the following configuration options:
http
: Enables the HTTP RPC server on the default port and interface (disabled by default).http-host
: The interface on which the HTTP RPC server will listen for requests. If skipped, it defaults tolocalhost
.http-port
: The port on which the HTTP server will listen for requests. If skipped, it defaults to6060
.
# Docker container
docker run -d \
--name juno \
-p 6060:6060 \
nethermind/juno \
--http \
--http-port 6060 \
--http-host 0.0.0.0
# Standalone binary
./build/juno --http --http-port 6060 --http-host 0.0.0.0
Making JSON-RPC requests
You can use any of Starknet's Node API Endpoints with Juno. Check the availability of Juno with the juno_version
method:
- Raw
- cURL
- Response
{
"jsonrpc": "2.0",
"method": "juno_version",
"params": [],
"id": 1
}
curl --location 'http://localhost:6060' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "juno_version",
"params": [],
"id": 1
}'
{
"jsonrpc": "2.0",
"result": "v0.11.7",
"id": 1
}
Get the most recent accepted block hash and number with the starknet_blockHashAndNumber
method:
- Raw
- cURL
- Starknet.js
- Starknet.go
- Starknet.rs
- Response
{
"jsonrpc": "2.0",
"method": "starknet_blockHashAndNumber",
"params": [],
"id": 1
}
curl --location 'http://localhost:6060' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "starknet_blockHashAndNumber",
"params": [],
"id": 1
}'
const { RpcProvider } = require("starknet");
const provider = new RpcProvider({
nodeUrl: "http://localhost:6060",
});
provider.getBlockLatestAccepted().then((blockHashAndNumber) => {
console.log(blockHashAndNumber);
});
package main
import (
"context"
"fmt"
"log"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/rpc"
"github.com/NethermindEth/starknet.go/utils"
)
func main() {
rpcUrl := "http://localhost:6060"
client, err := rpc.NewClient(rpcUrl)
if err != nil {
log.Fatal(err)
}
provider := rpc.NewProvider(client)
result, err := provider.BlockHashAndNumber(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Println("BlockHashAndNumber:", result)
}
use starknet::providers::{
jsonrpc::{HttpTransport, JsonRpcClient},
Provider, Url,
};
#[tokio::main]
async fn main() {
let provider = JsonRpcClient::new(HttpTransport::new(
Url::parse("http://localhost:6060").unwrap(),
));
let result = provider.block_hash_and_number().await;
match result {
Ok(block_hash_and_number) => {
println!("{block_hash_and_number:#?}");
}
Err(err) => {
eprintln!("Error: {err}");
}
}
}
{
"jsonrpc": "2.0",
"result": {
"block_hash": "0x637ae4d7468bb603c2f16ba7f9118d58c7d7c98a8210260372e83e7c9df443a",
"block_number": 640827
},
"id": 1
}
Supported Starknet API versions
Juno supports the following Starknet API versions:
- v0.7.0: Accessible via endpoints
/v0_7
,/rpc/v0_7
, or the default/
- v0.6.0: Accessible via endpoints
/v0_6
or/rpc/v0_6
To use a specific API version, specify the version endpoint in your RPC calls:
- Latest
- v0.7.0
- v0.6.0
curl --location 'http://localhost:6060' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "starknet_chainId",
"params": [],
"id": 1
}'
curl --location 'http://localhost:6060/v0_7' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "starknet_chainId",
"params": [],
"id": 1
}'
curl --location 'http://localhost:6060/v0_6' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "starknet_chainId",
"params": [],
"id": 1
}'