Skip to content

Simple Call

This guide demonstrates how to make simple read-only calls to Starknet contracts using Starknet.go.

Prerequisites

  • Go 1.18 or higher
  • Starknet.go installed
  • A Starknet node URL
  • Contract address

Code Example

package main
 
import (
    "context"
    "fmt"
    "github.com/NethermindEth/starknet.go"
)
 
func main() {
    // Initialize client
    client, err := starknet.NewClient("YOUR_NODE_URL")
    if err != nil {
        panic(err)
    }
 
    // Contract address
    contractAddress := "0x123..." // Your contract address
 
    // Prepare function call
    call := &starknet.FunctionCall{
        ContractAddress: contractAddress,
        EntryPoint:     "balanceOf",
        Calldata:       []string{"0x456..."}, // address
    }
 
    // Make the call
    result, err := client.Call(context.Background(), call)
    if err != nil {
        panic(err)
    }
 
    fmt.Printf("Call result: %v\n", result)
}

Explanation

  1. Initialize the Starknet client
  2. Define the contract address
  3. Prepare the function call with parameters
  4. Execute the call
  5. Process and display the result

Best Practices

  • Verify contract ABI before calling
  • Use proper error handling
  • Validate function parameters
  • Consider caching results for frequently called functions
  • Use appropriate context timeouts

Common Issues

  • Invalid contract address
  • Invalid function name
  • Invalid parameter types
  • Network connectivity issues
  • Contract reverted