DevNet Package
The DevNet package provides a client for interacting with Starknet DevNet - a local Starknet node for testing and development. This package enables developers to test smart contracts locally without deploying to testnets, with instant block times and full control over the network state.
:::danger DevNet Package is Broken
The DevNet package in starknet.go v0.17.0 is BROKEN and cannot work with any available DevNet version.The Accounts(), Mint(), and FeeToken() methods were designed for the deprecated Python starknet-devnet which:
- Had
/predeployed_accounts,/mint, and/fee_tokenendpoints - Is completely unavailable (removed from Docker Hub and PyPI)
- Has been replaced by starknet-devnet-rs (Rust version)
The current starknet-devnet-rs does NOT have these endpoints, causing EOF errors.
Only working methods:- ✅
NewDevNet()- Creates client instance - ✅
IsAlive()- Checks if DevNet is running - ❌
Accounts()- BROKEN (EOF error) - ❌
Mint()- BROKEN (endpoint doesn't exist) - ❌
FeeToken()- BROKEN (endpoint doesn't exist)
Required Workaround: Use the RPC provider directly to interact with DevNet. Get account credentials from DevNet startup logs:
docker logs starknet-devnet | grep "Account address":::
Overview
The DevNet package is designed to work with starknet-devnet-rs, a local Starknet node implementation written in Rust. It provides a simple Go client for:
- Network Management: Connect to and monitor DevNet instances
- Test Account Access: Retrieve pre-funded accounts for testing
- Token Minting: Create tokens for test scenarios
- Fee Token Information: Query the network's fee token details
- Health Monitoring: Verify DevNet availability and responsiveness
Key Components
Methods
- NewDevNet - Create a DevNet client instance
- IsAlive - Check if DevNet is running and accessible
- Accounts - Retrieve pre-funded test accounts
- Mint - Mint tokens to any address
- FeeToken - Get fee token metadata
Getting Started
To use the DevNet package, first ensure you have a running DevNet instance, then import the package:
import "github.com/NethermindEth/starknet.go/devnet"Quick Example (Working with RPC)
Due to API incompatibility, use the RPC provider to interact with DevNet:
package main
import (
"context"
"fmt"
"log"
"github.com/NethermindEth/starknet.go/devnet"
"github.com/NethermindEth/starknet.go/rpc"
)
func main() {
// Check if DevNet is running
devNet := devnet.NewDevNet()
if !devNet.IsAlive() {
log.Fatal("DevNet is not running. Start it with: starknet-devnet")
}
fmt.Println("✓ DevNet is running")
// Use RPC provider to interact with DevNet
provider, err := rpc.NewProvider(context.Background(), "http://localhost:5050/rpc")
if err != nil {
log.Fatal(err)
}
// Get chain ID to verify connection
chainID, err := provider.ChainID(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Connected to DevNet - Chain ID: %s\n", chainID)
// Get latest block number
blockNumber, err := provider.BlockNumber(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Latest block: %d\n", blockNumber)
}DevNet Setup
Before using this package, you need a running DevNet instance. There are several ways to set it up:
Using Cargo (Recommended)
# Install starknet-devnet-rs
cargo install starknet-devnet
# Run with default settings (localhost:5050)
starknet-devnet
# Run on custom port
starknet-devnet --port 5051
# Run with deterministic seed for reproducible accounts
starknet-devnet --seed 42Using Docker
# Pull the latest image
docker pull shardlabs/starknet-devnet-rs:latest
# Run DevNet (maps port 5050)
docker run -p 5050:5050 shardlabs/starknet-devnet-rs:latest
# Run with custom port
docker run -p 5051:5050 shardlabs/starknet-devnet-rs:latest --port 5050Using Docker Compose
Create a docker-compose.yml:
version: '3.8'
services:
starknet-devnet:
image: shardlabs/starknet-devnet-rs:latest
ports:
- "5050:5050"
command: --seed 42 --accounts 10Then run:
docker-compose up -dHow DevNet Works
Connection Model
The DevNet package uses a simple HTTP client to communicate with the DevNet server. When you create a DevNet instance with NewDevNet(), you're creating a client that points to a specific DevNet endpoint (default: http://localhost:5050).
Pre-funded Accounts
DevNet automatically creates pre-funded test accounts when it starts. These accounts:
- Are deployed and ready to use immediately
- Come with initial token balances for gas fees
- Have deterministic addresses when using the same seed
- Include private keys for signing transactions
- Typically default to 10 accounts (configurable)
Token Minting
Unlike testnets where you need faucets, DevNet allows unlimited token minting to any address. This enables:
- Setting up specific balance scenarios for testing
- Funding new accounts instantly
- Testing edge cases with extreme balances
- Resetting account balances between tests
Typical Testing Workflow
A common DevNet-based testing workflow:
- Start DevNet: Launch the DevNet server (cargo/docker)
- Connect: Create a DevNet client with
NewDevNet() - Health Check: Verify connection with
IsAlive() - Get Accounts: Retrieve test accounts with
Accounts() - Setup Balances: Mint tokens as needed with
Mint() - Create RPC Provider: Connect RPC client to DevNet
- Test Contracts: Deploy and interact with contracts
- Repeat: Reset or restart DevNet for clean test runs
Recommended Workflow: Using RPC Provider with DevNet
Since the DevNet package methods are incompatible, use the RPC provider directly:
package main
import (
"context"
"fmt"
"log"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/starknet.go/account"
"github.com/NethermindEth/starknet.go/devnet"
"github.com/NethermindEth/starknet.go/rpc"
)
func main() {
// Check DevNet is running
devNet := devnet.NewDevNet()
if !devNet.IsAlive() {
log.Fatal("DevNet is not running")
}
// Create RPC provider for DevNet
provider, err := rpc.NewProvider(context.Background(), "http://localhost:5050/rpc")
if err != nil {
log.Fatal(err)
}
// DevNet pre-funded account credentials (from starknet-devnet default accounts)
// You can get these by running: starknet-devnet and checking the console output
accountAddress, _ := new(felt.Felt).SetString("0x...") // Replace with actual DevNet account address
privateKey, _ := new(felt.Felt).SetString("0x...") // Replace with actual private key
publicKey, _ := new(felt.Felt).SetString("0x...") // Replace with actual public key
// Create keystore
ks := account.NewMemKeystore()
ks.Put(publicKey.String(), privateKey)
// Create account for signing transactions
acc, err := account.NewAccount(
provider,
accountAddress,
publicKey.String(),
ks,
account.CairoV2,
)
if err != nil {
log.Fatal(err)
}
// Verify account is ready
nonce, err := acc.Nonce(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Account ready! Nonce: %s\n", nonce.String())
fmt.Printf("Address: %s\n", accountAddress.String())
}Note: To get DevNet account credentials, run starknet-devnet and check the console output for pre-funded account addresses and private keys.
Use Cases
- Local Development: Test contract logic without testnet delays or costs
- Integration Testing: Run automated test suites against a local blockchain
- CI/CD Pipelines: Include blockchain testing in continuous integration
- Rapid Prototyping: Quickly iterate on contract designs with instant blocks
- Multi-Account Scenarios: Test complex interactions between multiple accounts
- State Management: Reset blockchain state between tests for reproducibility
- Fee Testing: Experiment with different fee scenarios using minting
Advantages of DevNet Testing
Speed
- Instant block times (no waiting for block inclusion)
- Immediate transaction finality
- No network latency
Cost
- Unlimited free tokens via minting
- No testnet faucet dependencies
- No gas costs
Control
- Deterministic account generation with seeds
- Full state reset capabilities
- Custom network configurations
- Isolated testing environment
Reproducibility
- Same seed = same accounts every time
- Consistent test environments
- Predictable contract addresses
:::tip Best Practices
Connection Management- Always check
IsAlive()before running tests to ensure DevNet is running - Use environment variables for DevNet URL to support different environments
- Implement connection retry logic for CI/CD pipelines
- Use different accounts for different roles (deployer, user, admin)
- Store account indices in test constants for clarity
- Consider using deterministic seeds for reproducible tests
- Restart DevNet between test suites for clean state
- Use
Mint()to set up specific balance scenarios - Document any shared state dependencies between tests
- Combine with RPC provider for full blockchain interaction
- Use Account package for transaction signing and submission
- Leverage Utils package for address and felt conversions :::
:::note Development Tips
Starting DevNet# Basic start
starknet-devnet
# With specific configuration
starknet-devnet --port 5051 --seed 42 --accounts 20
# With timeout for long-running tests
starknet-devnet --timeout 300// Default connection
devNet := devnet.NewDevNet()
// Custom URL
devNet := devnet.NewDevNet("http://localhost:5051")
// From environment
devNet := devnet.NewDevNet(os.Getenv("DEVNET_URL"))// Wait for DevNet to be ready
for i := 0; i < 10; i++ {
if devNet.IsAlive() {
break
}
time.Sleep(time.Second)
}:::
Related Packages
- RPC Provider - Interact with blockchain state and send transactions
- Account - Sign and submit transactions
- Utils - Convert between address formats and felt values
Version Compatibility
This documentation is based on starknet.go v0.17.0 and is compatible with:
- starknet-devnet-rs v0.1.0+
- Cairo 1.0+ contracts
- Starknet RPC spec v0.7.0+

