Skip to content

SpecVersion

Returns the version of the Starknet JSON-RPC specification being implemented by the node. This is useful for ensuring compatibility between your application and the RPC provider, as different specification versions may have different method signatures or behaviors.

Method Signature

func (provider *Provider) SpecVersion(ctx context.Context) (string, error)

Source: version.go

Parameters

  • ctx (context.Context): Context for request cancellation and timeout

Returns

  • string: The specification version (e.g., "0.7.0", "0.8.0", "0.9.0")
  • error: Error if the request fails

Usage Example

package main
 
import (
    "context"
    "fmt"
    "log"
    "os"
 
    "github.com/NethermindEth/starknet.go/rpc"
    "github.com/joho/godotenv"
)
 
func main() {
    // Load environment variables from .env file
    err := godotenv.Load()
    if err != nil {
        log.Fatal("Error loading .env file")
    }
 
    // Get RPC URL from environment variable
    rpcURL := os.Getenv("STARKNET_RPC_URL")
    if rpcURL == "" {
        log.Fatal("STARKNET_RPC_URL not found in .env file")
    }
 
    // Initialize provider
    provider, err := rpc.NewProvider(context.Background(), rpcURL)
    if err != nil {
        log.Fatal(err)
    }
 
    ctx := context.Background()
 
    // Get RPC specification version
    specVersion, err := provider.SpecVersion(ctx)
    if err != nil {
        log.Fatal(err)
    }
 
    fmt.Printf("RPC Spec Version: %s\n", specVersion)
}

Error Handling

specVersion, err := provider.SpecVersion(ctx)
if err != nil {
    log.Printf("Failed to get spec version: %v", err)
    return
}
 
fmt.Printf("Node implements RPC spec version: %s\n", specVersion)

Common Use Cases

  • Verifying your application is compatible with the node's RPC specification version.
  • Determining which RPC methods and features are available based on the spec version.
  • Logging specification version for debugging and support purposes.