The quickest way to start building on Ton 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 Ton Endpoint
Créez un compte Quicknode
Inscrivez-vous ici si ce n'est pas déjà fait.
Accédez à votre tableau de bord
Ouvrez le tableau de bord des endpoints depuis le menu latéral gauche pour gérer tous vos endpoints blockchain
Créez un nouvel endpoint
Click Create an Endpoint in the top-right corner, select Ton as your blockchain, then select your preferred network
Copiez vos URL de fournisseur
Gardez l'URL HTTP à portée de main. Vous l'utiliserez dans vos requêtes ci-dessous.
Pour une présentation détaillée du tableau de bord Quicknode, consultez notre guide
Envoyer votre première requête
Your endpoint is ready. Now, let's make your first call to the Ton blockchain. We'll use the getMasterchainInfo method, which retrieves masterchain information. 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 nativement. Ouvrez votre terminal et vérifiez la version de cURL en exécutant la commande ci-dessous :
curl --version
Send a GET request
In your terminal, copy and paste the following cURL command to retrieve the masterchain information:
curl --location 'YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo' \
--header 'accept: application/json'
Exemple de réponse
{
"ok": true,
"result": {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 12345678,
"root_hash": "abc123...",
"file_hash": "def456..."
}
}
Configurer votre projet
Tout d'abord, vérifiez que Node.js est installé avec la commande node --version. S'il n'est pas installé, téléchargez-le depuis https://nodejs.org. Ensuite, créez un nouveau répertoire et initialisez un projet Node.js :
mkdir ton-api-quickstart
cd ton-api-quickstart
npm init -y
Create your script
Create a new file called index.js and add the following code to retrieve the masterchain information:
const https = require('https');
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/getMasterchainInfo',
method: 'GET',
headers: {
'accept': 'application/json'
}
};
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.end();
Exécutez votre script
Execute your script in the terminal to retrieve the masterchain information:
node index.js
Configurer votre projet
First, verify Python is installed with python --version or python3 --version. Then create a new directory for your project:
mkdir ton-api-quickstart
cd ton-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
Installer les dépendances
Installez la bibliothèque « requests » pour effectuer des requêtes HTTP :
pip install requests
Create your script
Create a new file called main.py and add the following code to retrieve the masterchain information:
import requests
url = "YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo"
headers = {
'accept': 'application/json'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
Exécutez votre script
Execute your script in the terminal to retrieve the masterchain information:
python main.py
Configurer votre projet
First, create a new directory for your project:
mkdir ton-api-quickstart
cd ton-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 masterchain information:
require "uri"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["accept"] = "application/json"
response = https.request(request)
puts response.read_body
Exécutez votre script
Execute your script in the terminal to retrieve the masterchain information:
ruby main.rb
Si vous souhaitez en savoir plus sur la création de requêtes API, consultez nos guides et nos exemples d'applications.