SpecVersion
Returns the version of the Starknet JSON-RPC specification being used.
Method Signature
func (provider *Provider) SpecVersion(ctx context.Context) (string, error)Parameters
ctx- Context for request cancellation and timeout
Returns
string- The specification version (e.g., "0.8.1")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 spec version
specVersion, err := client.SpecVersion(ctx)
if err != nil {
log.Fatal("Failed to get spec version:", err)
}
fmt.Printf("Spec Version: %s\n", specVersion)
}Expected Output
Spec Version: 0.9.0Error Handling
specVersion, err := client.SpecVersion(ctx)
if err != nil {
// Handle error
return err
}
