Syncing
Gets the synchronization status of the node.
Method Signature
func (provider *Provider) Syncing(ctx context.Context) (SyncStatus, error)Parameters
ctx- Context for request cancellation and timeout
Returns
SyncStatus- Synchronization status (false if synced, or sync progress object)error- Error if the request fails
Usage Example
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/NethermindEth/starknet.go/rpc"
)
func main() {
// Get RPC URL from environment variable
rpcURL := os.Getenv("STARKNET_RPC_URL")
if rpcURL == "" {
log.Fatal("STARKNET_RPC_URL not set in environment")
}
ctx := context.Background()
client, err := rpc.NewProvider(ctx, rpcURL)
if err != nil {
log.Fatal("Failed to create client:", err)
}
// Get sync status
syncStatus, err := client.Syncing(ctx)
if err != nil {
log.Fatal("Failed to get sync status:", err)
}
// Check if node is syncing
if syncStatus.IsSyncing {
fmt.Printf("Node is syncing:\n")
fmt.Printf(" Starting Block Hash: %s\n", syncStatus.StartingBlockHash)
fmt.Printf(" Starting Block Num: %d\n", syncStatus.StartingBlockNum)
fmt.Printf(" Current Block Hash: %s\n", syncStatus.CurrentBlockHash)
fmt.Printf(" Current Block Num: %d\n", syncStatus.CurrentBlockNum)
fmt.Printf(" Highest Block Hash: %s\n", syncStatus.HighestBlockHash)
fmt.Printf(" Highest Block Num: %d\n", syncStatus.HighestBlockNum)
} else {
fmt.Println("Node is not syncing (fully synchronized)")
}
}Expected Output
Node is not syncing (fully synchronized)Error Handling
syncStatus, err := client.Syncing(ctx)
if err != nil {
// Handle error
return err
}Related Methods
- ChainID - Get chain ID
- SpecVersion - Get RPC specification version

