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
- Deploy accounts and contracts
- Execute contract functions
- Estimate transaction fees
- 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)
}- WebSocket example - Real-time subscriptions
- Read events example - Event filtering
- Simple call example - Contract state reads
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
- BlockNumber - Get latest block number
- BlockHashAndNumber - Get both hash and number
- BlockWithTxHashes - Block with transaction hashes only
- BlockWithTxs - Block with full transaction details
- BlockWithReceipts - Block with transactions and receipts
- BlockTransactionCount - Count transactions in a block
- StateUpdate - State changes in a block
- 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
- TransactionByHash - Get transaction by hash
- GetTransactionByBlockIdAndIndex - Get transaction by position
- TransactionReceipt - Get execution results
- GetTransactionStatus - Check status
- AddInvokeTransaction - Submit invoke transaction
- AddDeclareTransaction - Submit declare transaction
- AddDeployAccountTransaction - Submit deploy account transaction
- GetMessagesStatus - Check L1→L2 message status
Contract Methods
- Call - Read-only contract calls
- GetClass - Get contract class definition
- GetClassAt - Get class at address
- GetClassHashAt - Get class hash for address
- GetStorageAt - Read contract storage
- GetNonce - Get account nonce
- EstimateFee - Estimate transaction fees
- EstimateMessageFee - Estimate L1→L2 message fees
- StorageProof - Get storage Merkle proof
- CompiledCasm - Get compiled CASM class
Chain Information
- ChainID - Get chain identifier
- Syncing - Get node sync status
- SpecVersion - Get RPC spec version
Events
- Events - Query historical events (supports filtering by block range, contract address, event keys)
Debug & Tracing
- TraceTransaction - Get transaction execution trace
- TraceBlockTransactions - Trace all transactions in block
- SimulateTransaction - Simulate before sending
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
- Account Package - Transaction signing and sending (built on RPC)
- Client Package - Low-level JSON-RPC client
- DevNet Package - Local development utilities
Examples
- Deploy Account - Deploy a Starknet account
- Invoke Contract - Execute contract functions
- Read Events - Query and filter events
- Simple Call - Read contract state
- WebSocket - Real-time subscriptions
Reference
Implements Starknet RPC v0.9.0. Full API reference: pkg.go.dev

