Blast Chain Docs
  • Getting Started
    • Overview
    • User Guide
      • Setup
      • Bridge
      • Transfer Tokens
    • Blast Mainnet
      • Blast Block Explorer
      • Blast Bridge
  • Developers
    • Developer Quickstart
    • Interact with a node RPC
  • Verifying Smart Contracts
  • Contract Deployment Tutorial
  • Estimate gas fees
  • Running a Blast Node
  • Community
    • Telegram
    • X
Powered by GitBook
On this page
  1. Developers

Interact with a node RPC

If you’re a new Web3 developer, you might find that running your own full node is unnecessary, especially when you can connect to a public RPC service that simplifies the process.

Most developers prefer using a public RPC provider as it handles node requests and returns responses automatically. This is generally the fastest way to start developing, as it eliminates the complexities of managing your own node.

Send Your First Blockchain Request

To begin, ensure you have a Web3-enabled environment set up, such as a project configured with Web3.js or Ethers.js. Here's how to make your first blockchain request using the public RPC endpoint for Blast Chain:

Making a cURL Request

You can interact with the Blast blockchain using the JSON-RPC directly from your command line. For manual requests, use POST requests with the JSON-RPC. You'll need to include the Content-Type: application/json header and your query in the POST body with the following fields:

  • jsonrpc: This specifies the JSON-RPC version, which is currently 2.0.

  • method: The API method you wish to call. See Blast API reference for details.

  • params: A list of parameters to pass to the method.

  • id: Your request's ID, which will be echoed in the response to help track which request the response corresponds to.

Here’s an example command to run from your command line to retrieve the current gas price:

curl https://zkevmrpc.blastchain.org \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0", "method":"eth_gasPrice", "params":[], "id":1}'

Results

You should receive a response similar to this:

{ "id": 1, "jsonrpc": "2.0", "result": "0x77359400" }  // This is an example gas price.

This demonstrates a basic interaction with the Blast blockchain via the public RPC. You can expand upon this by integrating the RPC calls into your applications using a library like Web3.js or Ethers.js to automate interactions and create more complex functionalities.

Here's the revised section with the correct RPC URL for the Blast Chain:


Other Web3 Libraries

There are several Web3 libraries available that facilitate interaction with blockchain networks, including the Blast Chain. Below are instructions for configuring some of these libraries to connect to the Blast Chain using its public RPC:

Python with Web3.py

# Setup: pip install web3
from web3 import Web3
web3 = Web3(Web3.HTTPProvider("https://zkevmrpc.blastchain.org"))

Java with Web3j

// Setup: curl -L get.web3j.io | sh
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;

Web3j web3 = Web3j.build(new HttpService("https://zkevmrpc.blastchain.org"));

JavaScript with Ethers.js

// Setup: npm install ethers
const { ethers } = require("ethers");
const customHttpProvider = new ethers.providers.JsonRpcProvider("https://zkevmrpc.blastchain.org");

JavaScript with Web3.js

// Setup: npm install web3
const Web3 = require('web3');
const web3 = new Web3("https://zkevmrpc.blastchain.org");

These code snippets provide the necessary setup to connect various popular Web3 libraries to the Blast Chain using its official public RPC endpoint. Choose the library that aligns with your development preferences and start building on Blast Chain effectively.

PreviousDeveloper QuickstartNextVerifying Smart Contracts

Last updated 1 month ago