The quickest way to start building on Stellar 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 Stellar Endpoint
Criar uma Quicknode
Inscreve-te aqui, se ainda não o fizeste.
Aceda ao seu painel de controlo
Open the Endpoints dashboard from the left sidebar menu to manage all your blockchain endpoints
Criar um novo endpoint
Click Create an Endpoint in the top-right corner, select Stellar as your blockchain, then select your preferred network
Copie os URLs do seu fornecedor
Tenha a URL HTTP à mão. Vai precisar dela nas solicitações que se seguem.
Para um guia detalhado do Quicknode do Quicknode , consulte o nosso guia
Envie o seu primeiro pedido
Your endpoint is ready. Now, let's make your first call to the Stellar network. We'll use the getLatestLedger method, which retrieves information about the latest ledger on the network. Selecione o seu idioma preferido e siga os passos abaixo para enviar o seu primeiro pedido.
- cURL
- Node.js
Python
- Ruby
Verificar a instalação do cURL
Most *nix based systems have cURL support out of the box. Open your terminal and check the cURL version by running the command below:
curl --versão
Send a JSON-RPC request
In your terminal, copy and paste the following cURL command to retrieve the latest ledger information:
curl --location 'YOUR_QUICKNODE_ENDPOINT_URL/' \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 8675309,
"method": "getLatestLedger"
}'
Sample Response
{
"jsonrpc": "2.0",
"id": 8675309,
"result": {
"sequence": 12345678,
"hash": "abc123...",
"prevHash": "def456...",
"transactionCount": 42,
"operationCount": 128
}
}
Configure o seu projeto
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 stellar-api-quickstart
cd stellar-api-quickstart
npm init -y
Create your script
Create a new file called index.js and add the following code to retrieve the latest ledger information:
const https = require('https');
const data = JSON.stringify({
"jsonrpc": "2.0",
"id": 8675309,
"method": "getLatestLedger"
});
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 ledger information:
node index.js
Configure o seu projeto
First, verify Python is installed with python --version or python3 --version. Then create a new directory for your project:
mkdir stellar-api-quickstart
cd stellar-api-quickstart
Criar e ativar um ambiente virtual
Criar um ambiente virtual para gerir dependências:
python3 -m venv venv
source venv/bin/activate
Install dependencies
Instale a biblioteca `requests` para efetuar pedidos HTTP:
pip instalar requests
Create your script
Create a new file called main.py and add the following code to retrieve the latest ledger information:
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/"
payload = json.dumps({
"jsonrpc": "2.0",
"id": 8675309,
"method": "getLatestLedger"
})
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 ledger information:
python main.py
Configure o seu projeto
First, create a new directory for your project:
mkdir stellar-api-quickstart
cd stellar-api-quickstart
Verificar a instalação do Ruby
Verifique se o Ruby está instalado no seu sistema. Caso contrário, instale-o a partir de https://ruby-lang.org:
ruby --versão
Create your script
Create a new file called main.rb and add the following code to retrieve the latest ledger information:
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({
"jsonrpc": "2.0",
"id": 8675309,
"method": "getLatestLedger"
})
response = https.request(request)
puts response.read_body
Run your script
Execute your script in the terminal to retrieve the latest ledger information:
ruby main.rb
If you want to continue learning about making API requests, check out our guides and sample apps.