The quickest way to start building on Cosmos with QuickNode is by sending a JSON-RPC or REST/gRPC request to your endpoint. In this quickstart, you’ll create an endpoint, copy its provider URL, and make your first request. Code samples are available in cURL as well as popular SDKs and programming languages.
Get Your Cosmos Endpoint
Create a QuickNode account
Sign up here if you haven't already.
Go to your dashboard
Open the Endpoints dashboard from the left sidebar menu to manage all your blockchain endpoints
Create a new endpoint
Click Create an Endpoint in the top-right corner, select Cosmos as your blockchain, then select your preferred network
Copy your provider URLs
Keep the HTTP URL handy. You'll use it in your requests below.
For a detailed walkthrough of the QuickNode dashboard, check out our guide
Send Your First Request
Your endpoint is ready. Now, let's make your first call to the Cosmos blockchain. We’ll use the block_by_hash
method, which returns details of a specificed block when given a hash parameter. Select your preferred language or tool and follow the steps to send your request.
- cURL
- Node.js
- Python
- Ruby
Check cURL installation
Most *nix based systems have cURL support out of the box. Open your terminal and check the cURL version by running the command below:
curl --version
Query block by hash
Retrieve block information by hash from your QuickNode endpoint:
curl --location '<YOUR_QUICKNODE_ENDPOINT_URL>/block_by_hash?hash=0x645507DC48B4EF4BFF51826A0A5B73FD8CF926036AA4F6697D748FFC0B56D134'
Sample response
{
"jsonrpc": "2.0",
"id": -1,
"result": {
"block_id": { ... }
},
"block": {
"header": {
"version": {
"block": "11"
},
"chain_id": "cosmoshub-4",
"height": "20431644",
"time": "2024-05-15T01:23:57.786705041Z",
"last_block_id": { ... },
},
"data": {
"txs": [ ... ]
},
"evidence": {
"evidence": []
},
"last_commit": { ... }
}
}
}
Set up your project
Create a directory and initialize a Node.js project:
mkdir cosmos-js-quickstart
cd cosmos-js-quickstart
npm init -y
Create app.js
Use native fetch (Node.js 18+):
const requestOptions = { method: 'GET', redirect: 'follow' };
async function main() {
try {
const url = '<YOUR_QUICKNODE_ENDPOINT_URL>/block_by_hash?hash=0x645507DC48B4EF4BFF51826A0A5B73FD8CF926036AA4F6697D748FFC0B56D134';
const res = await fetch(url, requestOptions);
const text = await res.text();
console.log('Block information:', text);
} catch (err) {
console.error('Error:', err);
}
}
main();
Run
Execute your script:
node app.js
Set up your project
Create a new directory for your Python project:
mkdir cosmos-python-quickstart
cd cosmos-python-quickstart
Create and activate a virtual environment
Create a virtual environment to manage dependencies:
python3 -m venv venv
source venv/bin/activate
Install requests
Install the requests library for making HTTP requests:
pip install requests
Create a Python script (app.py)
Create a Python file with the following code:
import requests
url = '<YOUR_QUICKNODE_ENDPOINT_URL>/block_by_hash?hash=0x645507DC48B4EF4BFF51826A0A5B73FD8CF926036AA4F6697D748FFC0B56D134'
resp = requests.get(url)
print('Block information:')
print(resp.text)
Run the script
Execute your Python script:
python app.py
Set up your project
Create a new directory for your Ruby project:
mkdir cosmos-ruby-quickstart
cd cosmos-ruby-quickstart
Check Ruby Installation
Verify Ruby is installed on your system. If not, install it from https://ruby-lang.org:
ruby --version
Create a Ruby script (main.rb)
Create a main.rb file with the following code:
require 'uri'
require 'net/http'
url = URI('<YOUR_QUICKNODE_ENDPOINT_URL>/block_by_hash?hash=0x645507DC48B4EF4BFF51826A0A5B73FD8CF926036AA4F6697D748FFC0B56D134')
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
req = Net::HTTP::Get.new(url)
res = https.request(req)
puts 'Block information:'
puts res.body
Run the script
Execute your Ruby script to retrieve block information:
ruby main.rb
If you want to continue learning about making API requests, check out our guides and sample apps.
We ❤️ Feedback!
If you have any feedback or questions about this documentation, let us know. We'd love to hear from you!