The quickest way to start building on Fuel with Quicknode is by sending a GraphQL 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 Fuel Endpoint
如需了解 Quicknode 儀表板的詳細操作指南,請參閱我們的 指南
發送您的第一個請求
Your endpoint is ready. Now, let's make your first call to the Fuel blockchain. We'll use the getChainName query, which retrieves the name of the blockchain network. 請選擇您偏好的語言,並依照以下步驟提交您的第一個請求.
- cURL
- Node.js
Python
- TypeScript
- Apollo Client
- Ruby
檢查 cURL 的安裝狀況
大多數基於 *nix 的系統預設即支援 cURL。請開啟終端機,並執行以下指令以檢查 cURL 的版本:
curl --version
Get chain name
Retrieve the chain name using the getChainName query:
curl --location 'YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"query": "{ chain { name } }"}'
設定您的專案
Create a directory and initialize a Node.js project:
mkdir fuel-js-quickstart
cd fuel-js-quickstart
npm init -y
Create app.js
Create a file named app.js to call the getChainName query:
const https = require('https');
const data = JSON.stringify({
"query": "{ chain { name } }"
});
const options = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v1/graphql',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let result = '';
res.on('data', (chunk) => {
result += chunk;
});
res.on('end', () => {
console.log('Chain name:', result);
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
Run
Execute your script:
node app.js
設定您的專案
為您的 Python 專案建立一個新目錄:
mkdir fuel-python-quickstart
cd fuel-python-quickstart
建立並啟用虛擬環境
建立一個虛擬環境來管理依賴項:
python3 -m venv venv
source venv/bin/activate
安裝請求
安裝 requests 函式庫以進行 HTTP 請求:
pip 安裝 requests
建立一個 Python 腳本(app.py)
Create a Python file to call the getChainName query:
import requests
import json
url = "YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql"
payload = json.dumps({
"query": "{ chain { name } }"
})
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print('Chain name:')
print(response.text)
Run
Execute your script:
python app.py
設定您的專案
Create a directory and initialize a TypeScript project:
mkdir fuel-ts-quickstart
cd fuel-ts-quickstart
npm init -y
npm install typescript @types/node tsx
npx tsc --init
Create app.ts
Create a file named app.ts to call the getChainName query:
import https from 'https';
interface GraphQLResponse {
data: {
chain: {
name: string;
};
};
}
const data = JSON.stringify({
query: "{ chain { name } }"
});
const options: https.RequestOptions = {
hostname: '{your-endpoint-name}.quiknode.pro',
path: '/{your-token}/v1/graphql',
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let result = '';
res.on('data', (chunk: Buffer) => {
result += chunk.toString();
});
res.on('end', () => {
const response: GraphQLResponse = JSON.parse(result);
console.log('Chain name:', response.data.chain.name);
});
});
req.on('error', (error: Error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
Run
Execute your script:
npx tsx app.ts
設定您的專案
Create a directory and install Apollo Client:
mkdir fuel-apollo-quickstart
cd fuel-apollo-quickstart
npm init -y
npm install @apollo/client graphql cross-fetch
Create app.js
Create a file named app.js to query using Apollo Client:
const { ApolloClient, InMemoryCache, gql, HttpLink } = require('@apollo/client');
const fetch = require('cross-fetch');
const client = new ApolloClient({
link: new HttpLink({
uri: 'YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql',
fetch,
}),
cache: new InMemoryCache(),
});
const GET_CHAIN_NAME = gql`
query GetChainName {
chain {
name
}
}
`;
client
.query({
query: GET_CHAIN_NAME,
})
.then((result) => {
console.log('Chain name:', result.data.chain.name);
})
.catch((error) => {
console.error('Error:', error);
});
Run
Execute your script:
node app.js
設定您的專案
為您的 Ruby 專案建立一個新目錄:
mkdir fuel-ruby-quickstart
cd fuel-ruby-quickstart
檢查 Ruby 的安裝狀況
請確認您的系統上是否已安裝 Ruby。若尚未安裝,請從 https://ruby-lang.org 進行安裝:
ruby --version
Create a Ruby script (app.rb)
Create an app.rb file to call the getChainName query:
require "uri"
require "json"
require "net/http"
url = URI("YOUR_QUICKNODE_ENDPOINT_URL/v1/graphql")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Accept"] = "application/json"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"query": "{ chain { name } }"
})
response = https.request(request)
result = JSON.parse(response.read_body)
puts "Chain name:"
puts result["data"]["chain"]["name"]
執行該腳本
Execute your Ruby script:
ruby app.rb
如果您想進一步了解如何發送 API 請求,請參閱我們的指南和 範例應用程式。
我們 ❤️ 您的回饋!
如果您對這份文件有任何意見或疑問,請告訴我們。我們非常樂意聽取您的意見!