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);
运行
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 请求,请查看我们的指南和示例应用。
我们 ❤️ 您的反馈!
如果您对本文档有任何反馈或疑问,请告诉我们。我们非常期待您的反馈!