The quickest way to start building on Solana 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 Solana Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the Solana blockchain. We’ll use the getSlot method, which returns the slot number. 請選擇您偏好的語言或 SDK,並依照以下步驟發送您的第一個請求.
- cURL
- Solana Kit (@solana/kit)
- Solana-Web3.js
Solana.py
- Solana 命令列介面 (CLI)
Get Slot
To run the cURL request, open a terminal window and paste the following code to retrieve the current slot.
curl 'YOUR_QUICKNODE_ENDPOINT_URL/' \
-X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","id":1, "method":"getSlot"}'
設定您的專案
建立一個新目錄並初始化一個 Node.js 專案(假設已安裝 Node.js):
mkdir solana-quickstart
cd solana-quickstart
npm init -y
Install Solana Kit
Install the Solana Kit SDK for blockchain interaction:
npm install --save @solana/kit
建立您的主檔案
Create an index.ts file with the following code:
import { createSolanaRpc } from "@solana/kit";
(async () => {
const solanaRpc = createSolanaRpc("YOUR_QUICKNODE_ENDPOINT_URL/");
try {
const slot = await solanaRpc.getSlot().send();
console.log(slot);
} catch (error) {
console.error("Error fetching slot:", error);
}
})();
執行您的專案
Execute your script to see the current slot:
npx tsx index.ts
設定您的專案
建立一個新目錄並初始化一個 Node.js 專案(假設已安裝 Node.js):
mkdir solana-quickstart
cd solana-quickstart
npm init -y
Install Solana Web3.js SDK
Install the Solana JavaScript SDK for blockchain interaction:
npm install --save @solana/web3.js
建立您的主檔案
建立一個名為 index.js 的檔案,並輸入以下程式碼:
const web3 = require("@solana/web3.js");
(async () => {
const solana = new web3.Connection("YOUR_QUICKNODE_ENDPOINT_URL/");
const slot = await solana.getSlot();
console.log('Current slot:', slot);
})();
執行您的專案
Execute your script to see the current slot number:
node index.js
設定您的專案
Create a new directory for your Solana Python project:
mkdir solana-python-quickstart
cd solana-python-quickstart
Install Solana.py (if not already installed)
Check if solana is installed with `pip list | grep solana`. If not found, install it:
pip install solana cachetools
Create and run Python script
Create an app.py file with the following code, then execute it with `python app.py` to retrieve the current slot number:
from solana.rpc.api import Client
solana_client = Client("YOUR_QUICKNODE_ENDPOINT_URL/")
slot_response = solana_client.get_slot()
print(f"Current slot: {slot_response.value}")
Get current slot
solana slot --url YOUR_QUICKNODE_ENDPOINT_URL/
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。
我們 ❤️ 您的回饋!
如果您對這份文件有任何意見或疑問,請告訴我們。我們非常樂意聽取您的意見!