The quickest way to start building on Starknet 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 popular SDKs and programming languages.
Get Your Starknet 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 Starknet 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 Starknet blockchain. We'll use the starknet_blockNumber method, which returns the latest block number. Select your preferred language or SDK and follow the steps below to send your first request.
- cURL
- JavaScript
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 block number:
curl -X POST YOUR_QUICKNODE_ENDPOINT_URL/rpc/v0_9 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"starknet_blockNumber","params":[],"id":1}'
Sample Response
{
"id": 1,
"jsonrpc": "2.0",
"result": 2004149
}
Configure o seu projeto
Create a new directory and initialize a Node.js project:
mkdir starknet-js-quickstart
cd starknet-js-quickstart
npm init -y
Create a JavaScript file (app.js)
Add the code into your JavaScript file and execute the file in your terminal with the `node fileName.js` to retrieve the current block number.
const https = require('https');
const data = JSON.stringify({
"id": 1,
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": []
});
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/rpc/v0_9',
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();
Executar o script
Execute your JavaScript script:
node app.js
Configure o seu projeto
Crie um novo diretório para o seu projeto em Python:
mkdir starknet-python-quickstart
cd starknet-python-quickstart
Criar e ativar um ambiente virtual
Criar um ambiente virtual para gerir dependências:
python3 -m venv venv
source venv/bin/activate
Pedidos de instalação
Instale a biblioteca `requests` para efetuar pedidos HTTP:
pip instalar requests
Crie um script em Python (app.py)
To run the Python code below, add the code to a file and execute it with the `python file.py` command in your terminal window.
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/rpc/v0_9"
payload = json.dumps({
"id": 1,
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": []
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Executar o script
Execute your Python script:
python app.py
Configure o seu projeto
Crie um novo diretório para o seu projeto Ruby:
mkdir starknet-ruby-quickstart
cd starknet-ruby-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 a Ruby script (main.rb)
Create a main.rb file with the following code:
require "uri"
require "json"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/rpc/v0_9")
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({
"id": 1,
"jsonrpc": "2.0",
"method": "starknet_blockNumber",
"params": []
})
response = https.request(request)
result = JSON.parse(response.read_body)
puts "Block number: #{result["result"]}"
Executar o script
Execute your Ruby script to see the current block number:
ruby main.rb
If you want to continue learning about making API requests, check out our guides and sample apps.