The quickest way to start building on Linea 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 Linea Endpoint
Quicknode 계정 만들기
아직 가입하지 않으셨다면 여기에서 가입해 주세요.
대시보드로 이동하세요
왼쪽 사이드바 메뉴에서 ‘엔드포인트’ 대시보드를 열어 모든 블록체인 엔드포인트를 관리하세요
새 엔드포인트 생성
Click Create an Endpoint in the top-right corner, select linea as your blockchain, then select your preferred network
서비스 제공업체 URL을 복사하세요
HTTP URL을 잘 챙겨 두세요. 아래에서 요청을 보낼 때 이 URL을 사용하게 될 것입니다.
Quicknode 대시보드에 대한 자세한 사용 방법은 당사의 가이드를 확인해 주세요
첫 요청 보내기
Your endpoint is ready. Now, let's make your first call to the Linea blockchain. We’ll use the eth_blockNumber 최신 블록 번호를 반환하는 메서드입니다. 원하는 언어 또는 SDK를 선택한 후, 아래 단계를 따라 첫 번째 요청을 보내보세요..
- cURL
- Quicknode SDK
파이썬
- 자바스크립트
- 루비
- 가기
- Ethers.js
Web3.py
- Eth.rb
- Ethgo
cURL 설치 상태 확인
대부분의 *nix 기반 시스템은 기본적으로 cURL을 지원합니다. 터미널을 열고 아래 명령어를 실행하여 cURL 버전을 확인하세요:
curl --version
JSON-RPC 요청 보내기
터미널에서 다음 cURL 명령어를 복사하여 붙여넣어 최신 블록 번호를 확인하세요:
curl -X POST YOUR_QUICKNODE_ENDPOINT_URL/ \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
답변 예시
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1234567"
}
프로젝트 설정하기
먼저, `node --version` 명령어를 실행하여 Node.js가 설치되어 있는지 확인하세요. 설치되어 있지 않다면 https://nodejs.org에서 다운로드하세요. 그런 다음 새 디렉터리를 생성하고 Node.js 프로젝트를 초기화하세요:
mkdir linea-api-quickstart
cd linea-api-quickstart
npm init -y
Quicknode SDK 설치하기
Quicknode SDK 패키지를 설치합니다:
npm 설치 @quicknode/sdk
메인 파일 만들기
코드를 담을 index.js 파일을 생성하세요:
touch index.js
이 코드를 index.js 파일에 추가하세요
이 코드를 복사하여 index.js 파일에 붙여넣으세요:
const { Core } = require('@quicknode/sdk');
const main = async () => {
const core = new Core({
endpointUrl: 'YOUR_QUICKNODE_ENDPOINT_URL/',
});
const blockNumber = await core.client.request({
method: 'eth_blockNumber',
});
console.log('Block number:', parseInt(blockNumber, 16));
};
main();
프로젝트 실행하기
스크립트를 실행하여 최신 블록 번호를 확인하세요:
node index.js
프로젝트 설정하기
Python 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-python-quickstart
cd linea-python-quickstart
가상 환경 생성 및 활성화
의존성을 관리하기 위한 가상 환경을 생성합니다:
python3 -m venv venv
source venv/bin/activate
설치 요청
HTTP 요청을 보내기 위해 requests 라이브러리를 설치하세요:
pip 설치 requests
파이썬 스크립트(app.py)를 만듭니다.
다음 코드가 포함된 Python 파일을 만드세요:
import requests
import json
# Your Quicknode endpoint URL
endpoint_url = "YOUR_QUICKNODE_ENDPOINT_URL/"
# JSON-RPC request payload
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "eth_blockNumber",
"params": []
}
# Make the request
response = requests.post(endpoint_url, json=payload)
result = response.json()
print("Latest block number (hex):", result["result"])
print("Latest block number (decimal):", int(result["result"], 16))
스크립트를 실행하세요
파이썬 스크립트를 실행하세요:
python app.py
프로젝트 설정하기
새 디렉터리를 만들고 Node.js 프로젝트를 초기화합니다:
mkdir linea-js-quickstart
cd linea-js-quickstart
npm init -y
자바스크립트 파일(app.js)을 만듭니다.
다음 코드가 포함된 app.js 파일을 생성하세요(Node.js 18 이상에서 사용할 수 있는 네이티브 fetch를 사용).
const url = 'YOUR_QUICKNODE_ENDPOINT_URL/';
const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_blockNumber',
params: [],
id: 1
})
};
async function main() {
try {
const response = await fetch(url, options);
const data = await response.json();
console.log('Block Number (hex):', data.result);
console.log('Block Number (decimal):', parseInt(data.result, 16));
} catch (error) {
console.error('Error:', error);
}
}
main();
스크립트를 실행하세요
자바스크립트 스크립트를 실행하세요:
node app.js
프로젝트 설정하기
Ruby 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-ruby-quickstart
cd linea-ruby-quickstart
Ruby 설치 상태 확인
시스템에 Ruby가 설치되어 있는지 확인하십시오. 설치되어 있지 않다면, https://ruby-lang.org에서 설치하십시오:
ruby --version
Ruby 스크립트(main.rb)를 만듭니다.
다음 코드가 포함된 main.rb 파일을 생성하세요:
require "uri"
require "json"
require "net/http"
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 = JSON.dump({
"method": "eth_blockNumber",
"params": [],
"id": 1,
"jsonrpc": "2.0"
})
response = https.request(request)
result = JSON.parse(response.read_body)
hex_result = result["result"]
decimal_result = hex_result.to_i(16)
puts "Block number (hex): #{hex_result}"
puts "Block number (decimal): #{decimal_result}"
스크립트를 실행하세요
Ruby 스크립트를 실행하여 최신 블록 번호를 확인하세요:
ruby main.rb
프로젝트 설정하기
Go 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-go-quickstart
cd linea-go-quickstart
고(Go) 설치 확인
시스템에 Go가 설치되어 있는지 확인하십시오. 설치되어 있지 않다면, https://golang.org에서 설치하십시오:
go version
Go 스크립트(main.go) 만들기
다음 코드가 포함된 main.go 파일을 생성하세요:
package main
import (
"encoding/json"
"fmt"
"strings"
"net/http"
"io/ioutil"
"strconv"
)
type Response struct {
Result string `json:"result"`
}
func main() {
url := "YOUR_QUICKNODE_ENDPOINT_URL/"
method := "POST"
payload := strings.NewReader(`{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}`)
client := &http.Client{}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
var response Response
err = json.Unmarshal(body, &response)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
// Convert hex to decimal
blockNumber, err := strconv.ParseInt(response.Result, 0, 64)
if err != nil {
fmt.Println("Error converting hex to decimal:", err)
return
}
fmt.Printf("Block number (hex): %s\n", response.Result)
fmt.Printf("Block number (decimal): %d\n", blockNumber)
}
스크립트를 실행하세요
Go 스크립트를 실행하여 최신 블록 번호를 확인하세요:
main.go를 실행하세요
프로젝트 설정하기
새 디렉터리를 만들고 Node.js 프로젝트를 초기화합니다(Node.js가 이미 설치되어 있다고 가정합니다):
mkdir linea-ethers-quickstart
cd linea-ethers-quickstart
npm init -y
npm pkg set type=module
ethers.js 설치하기
이더리움과 연동하기 위해 ethers.js 라이브러리를 설치하세요:
npm 설치 ethers
메인 파일(index.js)을 생성하세요
다음 코드가 포함된 index.js 파일을 만드세요:
import { ethers } from "ethers";
(async () => {
const provider = new ethers.JsonRpcProvider("YOUR_QUICKNODE_ENDPOINT_URL/");
const blockNum = await provider.getBlockNumber();
console.log('Current block number (decimal):', blockNum);
console.log('Block number (hex):', '0x' + blockNum.toString(16));
})();
프로젝트 실행하기
스크립트를 실행하여 최신 블록 번호를 확인하세요:
node index.js
프로젝트 설정하기
web3.py 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-web3py-quickstart
cd linea-web3py-quickstart
web3.py를 설치하세요 (아직 설치되지 않은 경우).
`pip list | grep web3` 명령어를 실행하여 web3.py가 설치되어 있는지 확인하세요. 설치되어 있지 않다면 다음과 같이 설치하세요:
pip 설치 web3
파이썬 스크립트(main.py)를 만드세요.
다음 코드가 포함된 main.py 파일을 생성하세요:
from web3 import Web3
w3 = Web3(Web3.HTTPProvider("YOUR_QUICKNODE_ENDPOINT_URL/"))
try:
latest_block_number = w3.eth.block_number
print(f"Latest Block Number: {latest_block_number}")
print(f"Block number (hex): {hex(latest_block_number)}")
except Exception as e:
print(f"Error: {e}")
프로젝트 설정하기
eth.rb 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-ethrb-quickstart
cd linea-ethrb-quickstart
eth.rb를 설치하십시오(아직 설치되지 않은 경우).
`gem list eth` 명령어를 실행하여 eth.rb가 설치되어 있는지 확인하세요. 설치되어 있지 않다면 다음과 같이 설치하세요:
gem 설치 eth
Ruby 스크립트(main.rb)를 만듭니다.
다음 코드가 포함된 main.rb 파일을 생성하세요:
require 'eth'
client = Eth::Client.create "YOUR_QUICKNODE_ENDPOINT_URL/"
begin
block_number = client.eth_block_number
hex_result = block_number["result"]
decimal_result = hex_result.to_i(16)
puts "Block number (hex): #{hex_result}"
puts "Block number (decimal): #{decimal_result}"
rescue => e
puts "Error: #{e.message}"
end
스크립트를 실행하세요
Ruby 스크립트를 실행하여 최신 블록 번호를 확인하세요:
ruby main.rb
프로젝트 설정하기
Ethgo 프로젝트를 위한 새 디렉터리를 생성하세요:
mkdir linea-ethgo-quickstart
cd linea-ethgo-quickstart
Go 모듈 초기화 및 ethgo 설치
의존성을 추적하기 위해 go.mod 파일을 생성한 다음, ethgo SDK를 설치하세요:
go mod init linea-ethgo-quickstart
go get github.com/umbracle/ethgo
go mod tidy
Go 스크립트(main.go) 만들기
다음 코드가 포함된 main.go 파일을 생성하세요:
package main
import (
"fmt"
"log"
"github.com/umbracle/ethgo/jsonrpc"
)
func main() {
client, err := jsonrpc.NewClient("YOUR_QUICKNODE_ENDPOINT_URL/")
if err != nil {
log.Fatalf("Failed to connect to Ethereum: %v", err)
}
blockNumber, err := client.Eth().BlockNumber()
if err != nil {
log.Fatalf("Failed to get latest block number: %v", err)
}
fmt.Printf("Latest block number (decimal): %d\n", blockNumber)
fmt.Printf("Latest block number (hex): 0x%x\n", blockNumber)
}
스크립트를 실행하세요
Go 스크립트를 실행하여 최신 블록 번호를 확인하세요:
main.go를 실행하세요
API 요청 방법에 대해 더 자세히 알아보고 싶으시다면, 당사의 가이드와 샘플 앱을 확인해 보세요.
여러분의 피드백을 ❤️ 환영합니다!
이 문서에 대한 의견이나 질문이 있으시면 언제든지 알려주세요. 여러분의 의견을 기다리고 있습니다!