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
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 Ton 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 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
- 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
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'
Ejemplo de respuesta
{
"ok": true,
"result": {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 12345678,
"root_hash": "abc123...",
"file_hash": "def456..."
}
}
Configura tu proyecto
En primer lugar, comprueba que Node.js esté instalado ejecutando el comando `node --version`. Si no está instalado, descárgalo desde https://nodejs.org. A continuación, crea un nuevo directorio e inicializa un proyecto de 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();
Ejecuta tu script
Execute your script in the terminal to retrieve the masterchain information:
nodo index.js
Configura tu proyecto
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
Crear y activar un entorno virtual
Crear un entorno virtual para gestionar las dependencias:
python3 -m venv venv
source venv/bin/activate
Install dependencies
Instala la biblioteca «requests» para realizar solicitudes HTTP:
pip instalar 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)
Ejecuta tu script
Execute your script in the terminal to retrieve the masterchain information:
python main.py
Configura tu proyecto
First, create a new directory for your project:
mkdir ton-api-quickstart
cd ton-api-quickstart
Comprobar la instalación de Ruby
Comprueba que Ruby esté instalado en tu sistema. Si no es así, instálalo desde https://ruby-lang.org:
ruby --versión
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
Ejecuta tu script
Execute your script in the terminal to retrieve the masterchain 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.