The quickest way to start building on Sui with Quicknode is by sending a JSON-RPC or REST/gRPC request to your endpoint. In this quickstart, you’ll create an endpoint, copy its provider URL, and make your first request. Code samples below use cURL and common languages.
Get Your Sui Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the Sui blockchain. We’ll use the sui_getChainIdentifier method, which returns the chain identifier string. Select your preferred language or tool and follow the steps to send your request.
- cURL
- Node.js
Python
檢查 cURL 的安裝狀況
大多數基於 *nix 的系統預設即支援 cURL。請開啟終端機,並執行以下指令以檢查 cURL 的版本:
curl --version
Get Sui chain identifier
Send a JSON-RPC request to retrieve the Sui chain identifier:
curl -X POST YOUR_QUICKNODE_ENDPOINT_URL/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"sui_getChainIdentifier","params":[],"id":1}'
範例回應
{
"jsonrpc": "2.0",
"id": 1,
"result": "35834a8a"
}
設定您的專案
Create a directory and initialize a Node.js project:
mkdir sui-js-quickstart
cd sui-js-quickstart
npm init -y
Create app.js
Use native fetch (Node.js 18+):
const url = 'YOUR_QUICKNODE_ENDPOINT_URL/';
const payload = {
jsonrpc: '2.0',
method: 'sui_getChainIdentifier',
params: [],
id: 1,
};
async function main() {
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const data = await res.json();
console.log('Chain Identifier:', data.result);
}
main().catch(console.error);
Run
Execute your script:
node app.js
設定您的專案
為您的 Python 專案建立一個新目錄:
mkdir sui-python-quickstart
cd sui-python-quickstart
建立並啟用虛擬環境
建立一個虛擬環境來管理依賴項:
python3 -m venv venv
source venv/bin/activate
安裝請求
安裝 requests 函式庫以進行 HTTP 請求:
pip 安裝 requests
建立一個 Python 腳本(app.py)
建立一個包含以下程式碼的 Python 檔案:
import requests
import json
endpoint_url = "YOUR_QUICKNODE_ENDPOINT_URL/"
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "sui_getChainIdentifier",
"params": []
}
response = requests.post(endpoint_url, json=payload)
result = response.json()
print("Chain Identifier:", result.get("result"))
執行該腳本
執行您的 Python 腳本:
python app.py
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。
我們 ❤️ 您的回饋!
如果您對這份文件有任何意見或疑問,請告訴我們。我們非常樂意聽取您的意見!