The quickest way to start building on Aleo with Quicknode is by sending a REST API request to your endpoint. In this guide, 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 Aleo Endpoint
如需了解 Quicknode 仪表盘的详细操作指南,请参阅我们的 指南
发送您的第一个请求
Your endpoint is ready. Now, let's make your first call to the Aleo blockchain. We'll use the /block/height/latest endpoint, which returns the latest block height. 选择您首选的语言或 SDK,并按照以下步骤发送您的第一个请求.
- cURL
- Node.js
Python
- Ruby
检查 cURL 的安装情况
大多数基于 *nix 的系统默认都支持 cURL。打开终端,运行以下命令检查 cURL 的版本:
curl --version
Send a REST API request
In your terminal, copy and paste the following cURL command to retrieve the latest block height:
curl -X GET YOUR_QUICKNODE_ENDPOINT_URL/v2/mainnet/block/height/latest \
-H 'Accept: application/json'
示例回答
17473599
设置您的项目
首先,使用 `node --version` 命令验证 Node.js 是否已安装。如果尚未安装,请从 https://nodejs.org 下载。然后创建一个新目录并初始化一个 Node.js 项目:
mkdir aleo-api-quickstart
cd aleo-api-quickstart
npm init -y
创建主文件
为您的代码创建一个 index.js 文件:
touch index.js
将此代码添加到你的 index.js 文件中
Copy and paste this code into your index.js file to get the latest block height:
const https = require('https');
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v2/mainnet/block/height/latest',
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('Latest block height:', result);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.end();
Run your code
Save the file and run it in your terminal:
node index.js
Check Python installation
Verify Python is installed on your system. Open your terminal and run:
python --version
Install required packages
Install the requests library if you haven't already:
pip 安装 requests
Create your Python script
Create a new Python file and add the following code to get the latest block height:
import requests
url = "YOUR_QUICKNODE_ENDPOINT_URL/v2/mainnet/block/height/latest"
headers = {
'Accept': 'application/json'
}
response = requests.request("GET", url, headers=headers)
print("Latest block height:", response.text)
Run your script
Save the file as aleo_block_height.py and run it:
python aleo_block_height.py
检查 Ruby 安装情况
Verify Ruby is installed on your system. Open your terminal and run:
ruby --version
Create your Ruby script
Create a new Ruby file and add the following code to get the latest block height:
require 'net/http'
require 'json'
uri = URI('YOUR_QUICKNODE_ENDPOINT_URL/v2/mainnet/block/height/latest')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Accept'] = 'application/json'
response = http.request(request)
puts "Latest block height: #{response.body}"
Run your script
Save the file as aleo_block_height.rb and run it:
ruby aleo_block_height.rb
如果您想进一步了解如何发送 API 请求,请查看我们的指南和示例应用。
我们 ❤️ 您的反馈!
如果您对本文档有任何反馈或疑问,请告诉我们。我们非常期待您的反馈!