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 费用 method, which retrieves current fee information from the network. Select your preferred language and follow the steps below to send your first request.
- 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 请求,请查看我们的指南和示例应用。
我们 ❤️ 您的反馈!
如果您对本文档有任何反馈或疑问,请告诉我们。我们非常期待您的反馈!