The quickest way to start building on Polkadot with Quicknode is by sending a JSON-RPC 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 other popular programming languages.
Get Your Polkadot Endpoint
Créer un Quicknode
Inscrivez-vous ici si ce n'est pas déjà fait.
Accédez à votre tableau de bord
Ouvrez le tableau de bord « Endpoints » dans le menu de la barre latérale gauche pour gérer tous vos points de terminaison blockchain.
Créer un nouveau endpoint
Click Create an Endpoint in the top-right corner, select Polkadot as your blockchain, then select your preferred network
Copiez les URL de vos fournisseurs
Gardez l'URL HTTP à portée de main. Vous en aurez besoin dans les requêtes ci-dessous.
Pour découvrir en détail le Quicknode , consultez notre guide
Envoyez votre première demande
Your endpoint is ready. Now, let's make your first call to the Polkadot blockchain. We'll use the chain_getBlockHash method, which retrieves the hash of a specific block by its number. Select your preferred language and follow the steps below to send your first request.
- cURL
- Node.js
Python
- Ruby
Vérifier l'installation de cURL
La plupart des systèmes basés sur *nix prennent en charge cURL dès leur installation. Ouvrez votre terminal et vérifiez la version de cURL en exécutant la commande ci-dessous :
curl --version
Envoyer une requête JSON-RPC
In your terminal, copy and paste the following cURL command to retrieve the latest block hash:
curl -X POST YOUR_QUICKNODE_ENDPOINT_URL/ \
-H "Content-Type: application/json" \
-d '{"method":"chain_getBlockHash","params":[],"id":1,"jsonrpc":"2.0"}'
Exemple de réponse
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1234567890abcdef..."
}
Configurez votre projet
First, verify Node.js is installed with node --version. If not installed, download it from https://nodejs.org. Then create a new directory and initialize a Node.js project:
mkdir polkadot-api-quickstart
cd polkadot-api-quickstart
npm init -y
Create your script
Create a new file called index.js and add the following code to retrieve the latest block hash:
const https = require('https');
const data = JSON.stringify({
"method": "chain_getBlockHash",
"params": [],
"id": 1,
"jsonrpc": "2.0"
});
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let result = '';
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', () => {
console.log(result);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
Run your script
Execute your script in the terminal to retrieve the latest block hash:
node index.js
Configurez votre projet
First, verify Python is installed with python --version or python3 --version. Then create a new directory for your project:
mkdir polkadot-api-quickstart
cd polkadot-api-quickstart
Créer et activer un environnement virtuel
Créer un environnement virtuel pour gérer les dépendances :
python3 -m venv venv
source venv/bin/activate
Install dependencies
Installez la bibliothèque « requests » pour effectuer des requêtes HTTP :
pip installer requests
Create your script
Create a new file called main.py and add the following code to retrieve the latest block hash:
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/"
payload = json.dumps({
"method": "chain_getBlockHash",
"params": [],
"id": 1,
"jsonrpc": "2.0"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Run your script
Execute your script in the terminal to retrieve the latest block hash:
python main.py
Configurez votre projet
First, create a new directory for your project:
mkdir polkadot-api-quickstart
cd polkadot-api-quickstart
Vérifier l'installation de Ruby
Vérifiez que Ruby est bien installé sur votre système. Si ce n'est pas le cas, installez-le à partir du site https://ruby-lang.org :
ruby --version
Create your script
Create a new file called main.rb and add the following code to retrieve the latest block hash:
require "uri"
require "json"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"method": "chain_getBlockHash",
"params": [],
"id": 1,
"jsonrpc": "2.0"
})
response = https.request(request)
puts response.read_body
Run your script
Execute your script in the terminal to retrieve the latest block hash:
ruby main.rb
If you want to continue learning about making API requests, check out our guides and sample apps.