The quickest way to start building on Ton 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 Ton Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the Ton blockchain. We'll use the getMasterchainInfo method, which retrieves masterchain information. 請選擇您偏好的語言,並依照以下步驟提交您的第一個請求.
- cURL
- Node.js
Python
- Ruby
檢查 cURL 的安裝狀況
大多數基於 *nix 的系統預設即支援 cURL。請開啟終端機,並執行以下指令以檢查 cURL 的版本:
curl --version
Send a GET request
In your terminal, copy and paste the following cURL command to retrieve the masterchain information:
curl --location 'YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo' \
--header 'accept: application/json'
範例回應
{
"ok": true,
"result": {
"workchain": -1,
"shard": -9223372036854775808,
"seqno": 12345678,
"root_hash": "abc123...",
"file_hash": "def456..."
}
}
設定您的專案
首先,請使用 `node --version` 確認是否已安裝 Node.js。若尚未安裝,請從 https://nodejs.org 下載。接著建立一個新目錄,並初始化一個 Node.js 專案:
mkdir ton-api-quickstart
cd ton-api-quickstart
npm init -y
Create your script
Create a new file called index.js and add the following code to retrieve the masterchain information:
const https = require('https');
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/getMasterchainInfo',
method: 'GET',
headers: {
'accept': 'application/json'
}
};
const req = https.request(options, (res) => {
let result = '';
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', () => {
console.log(result);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.end();
Run your script
Execute your script in the terminal to retrieve the masterchain information:
node index.js
設定您的專案
First, verify Python is installed with python --version or python3 --version. Then create a new directory for your project:
mkdir ton-api-quickstart
cd ton-api-quickstart
建立並啟用虛擬環境
建立一個虛擬環境來管理依賴項:
python3 -m venv venv
source venv/bin/activate
Install dependencies
安裝 requests 函式庫以進行 HTTP 請求:
pip 安裝 requests
Create your script
Create a new file called main.py and add the following code to retrieve the masterchain information:
import requests
url = "YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo"
headers = {
'accept': 'application/json'
}
response = requests.request("GET", url, headers=headers)
print(response.text)
Run your script
Execute your script in the terminal to retrieve the masterchain information:
python main.py
設定您的專案
First, create a new directory for your project:
mkdir ton-api-quickstart
cd ton-api-quickstart
檢查 Ruby 的安裝狀況
請確認您的系統上是否已安裝 Ruby。若尚未安裝,請從 https://ruby-lang.org 進行安裝:
ruby --version
Create your script
Create a new file called main.rb and add the following code to retrieve the masterchain information:
require "uri"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/getMasterchainInfo")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["accept"] = "application/json"
response = https.request(request)
puts response.read_body
Run your script
Execute your script in the terminal to retrieve the masterchain information:
Ruby main.rb
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。