The quickest way to start building on Aptos 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 Aptos Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the Aptos blockchain. We'll use the v1 method, which returns information about the Aptos node. 請選擇您偏好的語言或 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 check if the Aptos node is healthy:
curl -X 'GET' 'YOUR_QUICKNODE_ENDPOINT_URL/v1/-/healthy' \
-H 'Content-Type: application/json'
範例回應
{
"message": "aptos-node:ok"
}
設定您的專案
首先,請使用 `node --version` 確認是否已安裝 Node.js。若尚未安裝,請從 https://nodejs.org 下載。接著建立一個新目錄,並初始化一個 Node.js 專案:
mkdir aptos-api-quickstart
cd aptos-api-quickstart
npm init -y
建立您的主檔案
為您的程式碼建立一個 index.js 檔案:
touch index.js
將這段程式碼加入您的 index.js 檔案中
Copy and paste this code into your index.js file to check if the Aptos node is healthy:
const https = require('https');
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v1/-/healthy',
method: 'GET',
headers: {
'Content-Type': '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();
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 check if the Aptos node is healthy:
import requests
url = "YOUR_QUICKNODE_ENDPOINT_URL/v1/-/healthy"
headers = {
'Content-Type': 'application/json'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
Run your script
Save the file as aptos_health.py and run it:
python aptos_health.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 check if the Aptos node is healthy:
require 'net/http'
require 'json'
uri = URI('YOUR_QUICKNODE_ENDPOINT_URL/v1/-/healthy')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Content-Type'] = 'application/json'
response = http.request(request)
puts response.body
Run your script
Save the file as aptos_health.rb and run it:
ruby aptos_health.rb
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。
我們 ❤️ 您的回饋!
如果您對這份文件有任何意見或疑問,請告訴我們。我們非常樂意聽取您的意見!