Skip to content

NewDevNet

Creates a new DevNet instance to interact with a local Starknet development network.

Function Signature

func NewDevNet(baseURL ...string) *DevNet

Source: devnet.go

Parameters

  • baseURL (optional) - Base URL of the DevNet server
    • If not provided, defaults to "http://localhost:5050"
    • Can be customized for different ports or hosts

Returns

  • *DevNet - Pointer to a new DevNet instance

Usage Example

package main
 
import (
	"fmt"
	"log"
	"os"
 
	"github.com/NethermindEth/starknet.go/devnet"
)
 
func main() {
	// Get DevNet URL from environment variable
	devnetURL := os.Getenv("DEVNET_URL")
	if devnetURL == "" {
		devnetURL = "http://localhost:5050"
	}
 
	// Create DevNet instance
	devNet := devnet.NewDevNet(devnetURL)
 
	fmt.Printf("DevNet instance created for: %s\n", devnetURL)
 
	// Verify connection
	if devNet.IsAlive() {
		fmt.Println("✓ DevNet is running")
	} else {
		log.Fatal("✗ DevNet is not running")
	}
}

Common Use Cases

Default Local DevNet

// Connect to default localhost:5050
devNet := devnet.NewDevNet()

Custom Port

// Connect to DevNet on custom port
devNet := devnet.NewDevNet("http://localhost:5051")

Docker Container

// Connect to DevNet in Docker
devNet := devnet.NewDevNet("http://devnet-container:5050")

Error Handling

The constructor itself doesn't return errors, but you should verify the connection:

devNet := devnet.NewDevNet()
 
if !devNet.IsAlive() {
	log.Fatal("DevNet is not running. Start it with: starknet-devnet")
}