Skip to main content

Celestia APIs & RPCs

πŸ“Note​

the port 26658 or 26658 is usually used for RPC request depending on node and network used (check nodes & networks section) To test tequests and outputs you can initially just paste the node link on your browser and browse the different methods you can use for your rquests , try the link rpc-mocha.pops.one it's a mocha test net Bridge node. visit docs.celestia.org/nodes/mocha-testnet for more , and experiment with different nodes and requests from your browser.

these reauests are not compatible with all networks/nodes

Often the RPC method is different from the API reauest method as demonstrated in the create wallet request

you need to have celestia-app or celestia-appd installed to perform RPC commands related to wallet management and other blockchain operations. The celestia-appd is the daemon for Celestia's application and is required to interact with the blockchain via RPC. Or else the methods will not be available


You can use your browser to get a node's endpoints suported functions and arguments and experiment with them try : http://public-celestia-mocha4-consensus.numia.xyz/

you can find more bridge node links on https://docs.celestia.org/nodes/mainnet#community-consensus-rpc-endpoints


examples of REST API and RPC Request​

🏦 Create Wallet

REST API Request:​

curl -X POST http://{{ node_ip }}:{{ node_port }}/create_wallet \
-H "Content-Type: application/json" \
-d '{"password": "{{ wallet_password }}"}'

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "keys.Add", "params": ["validator"], "id": 1}' | jq

πŸ” Query Balance

REST API Request:​

curl -X GET "http://{{ node_ip }}:{{ node_port }}/balance?address={{ your_address }}"

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "query.Balance", "params": ["{{ your_address }}"], "id": 1}' | jq

πŸ“ Submit Data Transaction

REST API Request:​

curl -X POST http://{{ node_ip }}:{{ node_port }}/submit_pfd \
-H "Content-Type: application/json" \
-d '{"namespace_id": "{{ namespace_id }}", "data": "{{ hex_data }}"}'

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "submit.DataTransaction", "params": ["{{ namespace_id }}", "{{ hex_data }}"], "id": 1}' | jq

Variables:

  • {{ node_ip }}: The IP address of the node.
  • {{ node_port }}: The port number of the node.
  • {{ wallet_password }}: The password for the wallet.
  • {{ your_address }}: Your wallet address.
  • {{ namespace_id }}: The namespace ID for the data transaction.
  • {{ hex_data }}: The hex-encoded data for the transaction.

To streamline the content by removing less important queries, I'll focus on keeping the most critical and frequently used queries. Here's the revised version:


πŸ“ˆ Query Data Availability

REST API Request:​

curl -X GET "http://{{ node_ip }}:{{ node_port }}/data_availability?height={{ block_height }}"

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "data.Availability", "params": ["{{ block_height }}"], "id": 1}' | jq

πŸ“ Query Latest Block Height

REST API Request:​

curl -X GET http://{{ node_ip }}:{{ node_port }}/block_height

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "block.LatestHeight", "params": [], "id": 1}' | jq

πŸ” Query Transaction by Hash

REST API Request:​

curl -X GET "http://{{ node_ip }}:{{ node_port }}/tx?hash={{ tx_hash }}"

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "transaction.GetByHash", "params": ["{{ tx_hash }}"], "id": 1}' | jq

πŸ” Query Staking Information

REST API Request:​

curl -X GET "http://{{ node_ip }}:{{ node_port }}/staking_info?address={{ your_address }}"

πŸ“‘ RPC Request:​

curl -s -X POST "http://{{ node_ip }}:{{ node_port }}" -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "staking.Info", "params": ["{{ your_address }}"], "id": 1}' | jq