Skip to main content

RPC Server

Introduction

Juno defines a JSON RPC 2.0 over HTTP. The spec is based on the starknet-spec repsitory, specifically the starknet_api_openrpc.json file.

Each request must be an HTTP POST to the /rpc endpoint, containing the JSON RPC request on its body data and the Content-Type header set with application/json value. JSON RPC 2.0 defines the request as follows:

With param list:

{
"jsonrpc": "2.0",
"id": 1,
"method": "method_name",
"params": [...]
}

Or with named params:

{
"jsonrpc": "2.0",
"id": 1,
"method": "method_name",
"params": {
"param1": "value1",
"param2": 12345,
"param3": true
}
}

Enabling RPC server

The RPC server is configured using the rpc section on the configuration file, see the configuration section.

Functions

starknet_getBlockWithTxHashes

Retrieves the block information and the list of all transaction hashes in the block.

Params

[block_id]

Param nameType
block_idBlockId

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getBlockWithTxHashes",
"params": ["0x047c3637b57c2b079b93c61539950c17e868a28f46cdef28f88521067f21e943"]
}

starknet_getBlockWithTxs

Retrieves the block information and the list of all transaction details in the block.

Params

[block_id]

Param nameType
block_idBlockId

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getBlockWithTxs",
"params": [2]
}

starknet_getStateUpdate

Get the information about the result of executing the requested block.

Params

[block_id]

Param nameType
block_idBlockId

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getStateUpdate",
"params": 0
}

starknet_getStorageAt

Get the value of the storage at the given address and key.

Params

[contract_address, key, block_id]

Param nameType
contract_addressFelt
keyStorageKey
block_idBlockId

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getStorageAt",
"params": [
"0x0735596016a37ee972c42adef6a3cf628c19bb3794369c65d2c82ba034aecf2c",
"0x0000000000000000000000000000000000000000000000000000000000000005",
"0x047c3637b57c2b079b93c61539950c17e868a28f46cdef28f88521067f21e943"
]
}

starknet_getTransactionByHash

Retrieves the transaction information.

Params

[transaction_hash]

Param nameType
transaction_hashFelt

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getTransactionByHash",
"params": ["0x00e0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75"]
}

starknet_getTransactionByBlockIdAndIndex

Get the details of the transaction given by the identified block and index in that block. If no transaction is found, null is returned.

Params

[block_id, index]

Param nameType
block_idBlockId
indexinteger

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_getTransactionByBlockIdAndIndex",
"params": [0, 1]
}

starknet_syncing

Retrieves information about the sync process status.

Example

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_syncing",
"params": []
}

starknet_healthCheck

Retrieves information of the health of the node.

Healthy node response

{
"jsonrpc": "2.0",
"id": 1,
"method": "starknet_healthCheck",
"params": []
}

Types

Felt

A Felt (field element) is Cairo's basic data type. A Felt is represented in RPC as a hexadecimal string that matches with this regular expression ^0x0[a-fA-F0-9]{1,63}$, some examples below:

  • 0x00e0a2e45a80bb827967e096bcf58874f6c01c191e0a0530624cba66a508ae75
  • 0x00
note

All Felts are returned with all characters (66 characters, including the 0x prefix), which means that the leading zero prefix is not removed. This is the zero Felt returned by the RPC 0x0000000000000000000000000000000000000000000000000000000000000000.

Follow this Cairo documentation link to know more about Felt.

BlockId

An identifier that represents a block. Can be one of these:

  • Block hash: the block hash string
  • Block number: non negative number
  • Block tag(string):
    • latest: refer to the latest block
    • pending: refer to the pending block

Storage Key

A storage key, represented as a string of hex digits (up to 62 hex digits, 3 bits, and 5 leading zeroes), matching with this regex: ^0x0[0-7]{1}[a-fA-F0-9]{0,62}$.