Skip to content

RPC Package

The RPC package provides direct access to Starknet's JSON-RPC API (v0.9.0 specification). Use it to query blockchain data, submit transactions, and subscribe to real-time updates.

What This Package Does

Query Blockchain Data
  • Fetch blocks and transactions
  • Read contract storage and state
  • Query event logs with filters
Submit Transactions
  • Deploy accounts and contracts
  • Execute contract functions
  • Estimate transaction fees
Real-time Updates
  • Subscribe to new blocks
  • Monitor contract events
  • Track transaction status

Getting Started

package main
 
import (
    "context"
    "fmt"
    "log"
 
    "github.com/NethermindEth/starknet.go/rpc"
)
 
func main() {
    client, err := rpc.NewProvider("https://starknet-sepolia.public.blastapi.io/rpc/v0_8")
    if err != nil {
        log.Fatal(err)
    }
 
    blockNumber, err := client.BlockNumber(context.Background())
    if err != nil {
        log.Fatal(err)
    }
 
    fmt.Printf("Latest block: %d\n", blockNumber)
}
See Also:

Core Components

Provider

HTTP client for standard RPC calls. Handles requests/responses for querying blocks, reading state, and submitting transactions.

WebSocketProvider

WebSocket client for subscriptions. Use this when you need real-time event streaming or block notifications.

Types

Type definitions for all RPC operations. Provides compile-time type safety for requests and responses.

Available Methods

Block Methods

Which method to use:
  • Just need the block number? Use BlockNumber()
  • Want minimal data? Use BlockWithTxHashes()
  • Need full transaction data? Use BlockWithTxs()
  • Analyzing execution results? Use BlockWithReceipts()

Transaction Methods

Contract Methods

Chain Information

Events

  • Events - Query historical events (supports filtering by block range, contract address, event keys)

Debug & Tracing

Network Support

Works with mainnet, testnet, and local devnets. Just change the RPC URL:

// Mainnet
mainnetClient, _ := rpc.NewProvider("https://starknet-mainnet.public.blastapi.io/rpc/v0_8")
 
// Sepolia Testnet
sepoliaClient, _ := rpc.NewProvider("https://starknet-sepolia.public.blastapi.io/rpc/v0_8")
 
// Local DevNet
devnetClient, _ := rpc.NewProvider("http://localhost:5050/rpc")

Related Packages

Examples

Reference

Implements Starknet RPC v0.9.0. Full API reference: pkg.go.dev