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
Crear una cuenta en Quicknode
Regístrate aquí si aún no lo has hecho.
Ve a tu panel de control
Abre el panel de control de Endpoints desde el menú de la barra lateral izquierda para gestionar todos tus puntos de conexión de la cadena de bloques
Crear un nuevo punto final
Click Create an Endpoint in the top-right corner, select Cosmos as your blockchain, then select your preferred network
Copia las URL de tus proveedores
Ten a mano la URL HTTP. La vas a utilizar en las solicitudes que vas a realizar a continuación.
Si quieres ver una explicación detallada del panel de control de Quicknode, echa un vistazo a nuestra guía
Envía tu primera solicitud
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
- Rubí
Comprobar la instalación de cURL
La mayoría de los sistemas basados en *nix son compatibles con cURL de serie. Abre el terminal y comprueba la versión de cURL ejecutando el siguiente comando:
curl --versión
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": { ... }
}
}
}
Configura tu proyecto
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();
Correr
Execute your script:
nodo app.js
Configura tu proyecto
Crea un nuevo directorio para tu proyecto de Python:
mkdir cosmos-python-quickstart
cd cosmos-python-quickstart
Crear y activar un entorno virtual
Crear un entorno virtual para gestionar las dependencias:
python3 -m venv venv
source venv/bin/activate
Solicitudes de instalación
Instala la biblioteca «requests» para realizar solicitudes HTTP:
pip instalar requests
Crea un script en Python (app.py)
Crea un archivo de Python con el siguiente código:
import requests
url = '<YOUR_QUICKNODE_ENDPOINT_URL>/block_by_hash?hash=0x645507DC48B4EF4BFF51826A0A5B73FD8CF926036AA4F6697D748FFC0B56D134'
resp = requests.get(url)
print('Block information:')
print(resp.text)
Ejecuta el script
Ejecuta tu script de Python:
python app.py
Configura tu proyecto
Crea un nuevo directorio para tu proyecto de Ruby:
mkdir cosmos-ruby-quickstart
cd cosmos-ruby-quickstart
Check Ruby Installation
Comprueba que Ruby esté instalado en tu sistema. Si no es así, instálalo desde https://ruby-lang.org:
ruby --versión
Crea un script en Ruby (main.rb)
Crea un archivo «main.rb» con el siguiente código:
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
Ejecuta el script
Execute your Ruby script to retrieve block information:
ruby main.rb
Si quieres seguir aprendiendo a realizar solicitudes a la API, echa un vistazo a nuestras guías y aplicaciones de ejemplo.
¡Nos encanta recibir comentarios!
Si tienes algún comentario o pregunta sobre esta documentación, háznoslo saber. ¡Nos encantaría saber tu opinión!