The quickest way to start building on zkSync 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 zkSync Endpoint
Create a QuickNode account
Sign up here if you haven't already.
Go to your dashboard
Open the Endpoints dashboard from the left sidebar menu to manage all your blockchain endpoints
Create a new endpoint
Click Create an Endpoint in the top-right corner, select zkSync as your blockchain, then select your preferred network
Copy your provider URLs
Keep the HTTP URL handy. You'll use it in your requests below.
For a detailed walkthrough of the QuickNode dashboard, check out our guide
Send Your First Request
Your endpoint is ready. Now, let's make your first call to the zkSync blockchain. We’ll use the eth_blockNumber
method, which returns the latest block number. Select your preferred language or SDK and follow the steps below to send your first request.
- cURL
- QuickNode SDK
- Python
- JavaScript
- Ruby
- Go
- Ethers.js
- Web3.py
- Eth.rb
- Ethgo
Check cURL installation
Most *nix based systems have cURL support out of the box. Open your terminal and check the cURL version by running the command below:
curl --version
Send a JSON-RPC request
In your terminal, copy and paste the following cURL command to retrieve the latest block number:
curl -X POST YOUR_QUICKNODE_ENDPOINT_URL \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
Sample Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x1234567"
}
Set up your project
First, verify Node.js is installed with node --version. If not installed, download it from https://nodejs.org. Then create a new directory and initialize a Node.js project:
mkdir zkSync-api-quickstart
cd zkSync-api-quickstart
npm init -y
Install the QuickNode SDK
Install the QuickNode SDK package:
npm install @quicknode/sdk
Create your main file
Create an index.js file for your code:
touch index.js
Add this code to your index.js file
Copy and paste this code into your index.js file:
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();
Run your project
Execute your script to see the latest block number:
node index.js
Set up your project
Create a new directory for your Python project:
mkdir zkSync-python-quickstart
cd zkSync-python-quickstart
Create and activate a virtual environment
Create a virtual environment to manage dependencies:
python3 -m venv venv
source venv/bin/activate
Install requests
Install the requests library for making HTTP requests:
pip install requests
Create a Python script (app.py)
Create a Python file with the following code:
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))
Run the script
Execute your Python script:
python app.py
Set up your project
Create a new directory and initialize a Node.js project:
mkdir zkSync-js-quickstart
cd zkSync-js-quickstart
npm init -y
Create a JavaScript file (app.js)
Create an app.js file with the following code (using native fetch available in Node.js 18+):
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();
Run the script
Execute your JavaScript script:
node app.js
Set up your project
Create a new directory for your Ruby project:
mkdir zkSync-ruby-quickstart
cd zkSync-ruby-quickstart
Check Ruby installation
Verify Ruby is installed on your system. If not, install it from https://ruby-lang.org:
ruby --version
Create a Ruby script (main.rb)
Create a main.rb file with the following code:
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}"
Run the script
Execute your Ruby script to see the latest block number:
ruby main.rb
Set up your project
Create a new directory for your Go project:
mkdir zkSync-go-quickstart
cd zkSync-go-quickstart
Check Go installation
Verify Go is installed on your system. If not, install it from https://golang.org:
go version
Create a Go script (main.go)
Create a main.go file with the following code:
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)
}
Run the script
Execute your Go script to see the latest block number:
go run main.go
Set up your project
Create a new directory and initialize a Node.js project (assumes Node.js is already installed):
mkdir zkSync-ethers-quickstart
cd zkSync-ethers-quickstart
npm init -y
npm pkg set type=module
Install ethers.js
Install the ethers.js library for Ethereum interaction:
npm install ethers
Create your main file (index.js)
Create an index.js file with the following code:
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));
})();
Run your project
Execute your script to see the latest block number:
node index.js
Set up your project
Create a new directory for your web3.py project:
mkdir zkSync-web3py-quickstart
cd zkSync-web3py-quickstart
Install web3.py (if not already installed)
Check if web3.py is installed with `pip list | grep web3`. If not found, install it:
pip install web3
Create a Python script (main.py)
Create a main.py file with the following code:
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}")
Set up your project
Create a new directory for your eth.rb project:
mkdir zkSync-ethrb-quickstart
cd zkSync-ethrb-quickstart
Install eth.rb (if not already installed)
Check if eth.rb is installed with `gem list eth`. If not found, install it:
gem install eth
Create a Ruby script (main.rb)
Create a main.rb file with the following code:
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
Run the script
Execute your Ruby script to see the latest block number:
ruby main.rb
Set up your project
Create a new directory for your Ethgo project:
mkdir zkSync-ethgo-quickstart
cd zkSync-ethgo-quickstart
Initialize Go module and install ethgo
Initialize a go.mod file to track dependencies, then install the ethgo SDK:
go mod init zkSync-ethgo-quickstart
go get github.com/umbracle/ethgo
go mod tidy
Create a Go script (main.go)
Create a main.go file with the following code:
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)
}
Run the script
Execute your Go script to see the latest block number:
go run main.go
If you want to continue learning about making API requests, check out our guides and sample apps.
We ❤️ Feedback!
If you have any feedback or questions about this documentation, let us know. We'd love to hear from you!