Client Configuration
The client configuration submodule provides functionality for configuring Starknet clients.
Client Configuration
The client configuration is represented by the ClientConfig
struct, which contains:
- Node URL
- Chain ID
- Timeout
- Retry configuration
- Logging configuration
Creating a Client
To create a new client:
config := client.ClientConfig{
NodeURL: "https://your-node-url",
ChainID: "SN_MAIN",
Timeout: 30 * time.Second,
}
client, err := client.NewClient(config)
if err != nil {
// Handle error
}
Configuration Options
Node URL
The node URL is the URL of the Starknet node to connect to:
config.NodeURL = "https://your-node-url"
Chain ID
The chain ID is the ID of the Starknet chain to connect to:
config.ChainID = "SN_MAIN"
Timeout
The timeout is the maximum time to wait for a response:
config.Timeout = 30 * time.Second
Retry Configuration
The retry configuration is used to configure retry behavior:
config.RetryConfig = client.RetryConfig{
MaxRetries: 3,
RetryDelay: 1 * time.Second,
}
Logging Configuration
The logging configuration is used to configure logging behavior:
config.LoggingConfig = client.LoggingConfig{
Level: "info",
Format: "json",
}
Example Usage
// Create a new client
config := client.ClientConfig{
NodeURL: "https://your-node-url",
ChainID: "SN_MAIN",
Timeout: 30 * time.Second,
RetryConfig: client.RetryConfig{
MaxRetries: 3,
RetryDelay: 1 * time.Second,
},
LoggingConfig: client.LoggingConfig{
Level: "info",
Format: "json",
},
}
client, err := client.NewClient(config)
if err != nil {
log.Fatal(err)
}
// Use the client
block, err := client.GetBlockByNumber(1)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Block hash: %s\n", block.Hash)