The quickest way to start building on XRPL 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 other popular programming languages.
Get Your XRPL Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the XRPL blockchain. We'll use the fee method, which retrieves current fee information from the network. 請選擇您偏好的語言,並依照以下步驟提交您的第一個請求.
- cURL
- Node.js
Python
- Ruby
檢查 cURL 的安裝狀況
大多數基於 *nix 的系統預設即支援 cURL。請開啟終端機,並執行以下指令以檢查 cURL 的版本:
curl --version
傳送一個 JSON-RPC 請求
In your terminal, copy and paste the following cURL command to retrieve current fee information:
curl YOUR_QUICKNODE_ENDPOINT_URL/ \
-X POST \
-H "Content-Type: application/json" \
--data '{
"method": "fee",
"params": [{}],
"id": 1,
"jsonrpc": "2.0"
}'
範例回應
{
"id": 1,
"status": "success",
"type": "response",
"result": {
"current_ledger_size": "56",
"current_queue_size": "0",
"drops": {
"base_fee": "10",
"median_fee": "5000",
"minimum_fee": "10",
"open_ledger_fee": "10"
},
"expected_ledger_size": "55",
"ledger_current_index": 75708765,
"levels": {
"median_level": "128000",
"minimum_level": "256",
"open_ledger_level": "256",
"reference_level": "256"
},
"max_queue_size": "1100"
}
}
設定您的專案
首先,請使用 `node --version` 確認是否已安裝 Node.js。若尚未安裝,請從 https://nodejs.org 下載。接著建立一個新目錄,並初始化一個 Node.js 專案:
mkdir xrpl-api-quickstart
cd xrpl-api-quickstart
npm init -y
建立您的主檔案
為您的程式碼建立一個 index.js 檔案:
touch index.js
將這段程式碼加入您的 index.js 檔案中
請將這段程式碼複製並貼到您的 index.js 檔案中:
const https = require('https');
const data = JSON.stringify({
method: "fee",
params: [{}],
id: 1,
jsonrpc: "2.0"
});
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log('XRPL Fee Information:');
console.log(JSON.stringify(JSON.parse(responseData), null, 2));
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
執行該腳本
Execute your Node.js script to retrieve fee information:
node index.js
設定您的專案
Create a new directory for your project:
mkdir xrpl-api-quickstart
cd xrpl-api-quickstart
建立並啟用虛擬環境
建立一個虛擬環境來管理依賴項:
python3 -m venv venv
source venv/bin/activate
Install required packages
Install the requests library:
pip 安裝 requests
建立一個 Python 腳本(main.py)
建立一個名為 main.py 的檔案,並輸入以下程式碼:
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/"
payload = {
"method": "fee",
"params": [{}],
"id": 1,
"jsonrpc": "2.0"
}
headers = {
'Content-Type': 'application/json'
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
print("XRPL Fee Information:")
print(json.dumps(data, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error making request: {e}")
except json.JSONDecodeError as e:
print(f"Error parsing JSON: {e}")
執行該腳本
Execute your Python script to retrieve fee information:
python main.py
設定您的專案
為您的 Ruby 專案建立一個新目錄:
mkdir xrpl-ruby-quickstart
cd xrpl-ruby-quickstart
Check Ruby Installation
請確認您的系統上是否已安裝 Ruby。若尚未安裝,請從 https://ruby-lang.org 進行安裝:
ruby --version
建立一個 Ruby 腳本(main.rb)
建立一個名為 main.rb 的檔案,並輸入以下程式碼:
require 'uri'
require 'net/http'
require 'json'
url = URI('YOUR_QUICKNODE_ENDPOINT_URL/')
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request['Content-Type'] = 'application/json'
request.body = {
method: "fee",
params: [{}],
id: 1,
jsonrpc: "2.0"
}.to_json
begin
response = https.request(request)
if response.is_a?(Net::HTTPSuccess)
data = JSON.parse(response.body)
puts 'XRPL Fee Information:'
puts JSON.pretty_generate(data)
else
puts "HTTP Error: #{response.code} - #{response.message}"
end
rescue JSON::ParserError => e
puts "JSON parsing error: #{e.message}"
rescue => e
puts "Error: #{e.message}"
end
執行該腳本
Execute your Ruby script to retrieve fee information:
Ruby main.rb
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。
我們 ❤️ 您的回饋!
如果您對這份文件有任何意見或疑問,請告訴我們。我們非常樂意聽取您的意見!