The quickest way to start building on Fuel with Quicknode is by sending a GraphQL 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 Fuel 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 Fuel 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 Fuel blockchain. We'll use the getChainName query, which retrieves the name of the blockchain network. Select your preferred language and follow the steps below to send your first request.
- cURL
- Node.js
Python
- TypeScript
- Apollo Client
- 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
Get chain name
Retrieve the chain name using the getChainName query:
curl --location 'YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"query": "{ chain { name } }"}'
Configura tu proyecto
Create a directory and initialize a Node.js project:
mkdir fuel-js-quickstart
cd fuel-js-quickstart
npm init -y
Create app.js
Create a file named app.js to call the getChainName query:
const https = require('https');
const data = JSON.stringify({
"query": "{ chain { name } }"
});
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v1/graphql',
method: 'POST',
headers: {
'Accept': 'application/json',
'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('Chain name:', result);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
Correr
Execute your script:
nodo app.js
Configura tu proyecto
Crea un nuevo directorio para tu proyecto de Python:
mkdir fuel-python-quickstart
cd fuel-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)
Create a Python file to call the getChainName query:
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql"
payload = json.dumps({
"query": "{ chain { name } }"
})
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print('Chain name:')
print(response.text)
Correr
Execute your script:
python app.py
Configura tu proyecto
Create a directory and initialize a TypeScript project:
mkdir fuel-ts-quickstart
cd fuel-ts-quickstart
npm init -y
npm install typescript @types/node tsx
npx tsc --init
Create app.ts
Create a file named app.ts to call the getChainName query:
import https from 'https';
interface GraphQLResponse {
data: {
chain: {
name: string;
};
};
}
const data = JSON.stringify({
query: "{ chain { name } }"
});
const options: https.RequestOptions = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v1/graphql',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let result = '';
res.on('data', (chunk: Buffer) => {
result += chunk.toString();
});
res.on('end', () => {
const response: GraphQLResponse = JSON.parse(result);
console.log('Chain name:', response.data.chain.name);
});
});
req.on('error', (error: Error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
Correr
Execute your script:
npx tsx app.ts
Configura tu proyecto
Create a directory and install Apollo Client:
mkdir fuel-apollo-quickstart
cd fuel-apollo-quickstart
npm init -y
npm install @apollo/client graphql cross-fetch
Create app.js
Create a file named app.js to query using Apollo Client:
const { ApolloClient, InMemoryCache, gql, HttpLink } = require('@apollo/client');
const fetch = require('cross-fetch');
const client = new ApolloClient({
link: new HttpLink({
uri: 'YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql',
fetch,
}),
cache: new InMemoryCache(),
});
const GET_CHAIN_NAME = gql`
query GetChainName {
chain {
name
}
}
`;
client
.query({
query: GET_CHAIN_NAME,
})
.then((result) => {
console.log('Chain name:', result.data.chain.name);
})
.catch((error) => {
console.error('Error:', error);
});
Correr
Execute your script:
nodo app.js
Configura tu proyecto
Crea un nuevo directorio para tu proyecto de Ruby:
mkdir fuel-ruby-quickstart
cd fuel-ruby-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 a Ruby script (app.rb)
Create an app.rb file to call the getChainName query:
require "uri"
require "json"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"query": "{ chain { name } }"
})
response = https.request(request)
result = JSON.parse(response.read_body)
puts "Chain name:"
puts result["data"]["chain"]["name"]
Ejecuta el script
Execute your Ruby script:
ruby app.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!