Skip to content

FeeToken

Retrieves information about the fee token used on the DevNet.

Method Signature

func (devnet *DevNet) FeeToken() (*FeeToken, error)

Source: devnet.go

Parameters

None

Returns

  • *FeeToken - Contains symbol and address of the fee token
  • error - Error if the request fails

FeeToken Structure

type FeeToken struct {
    Symbol  string
    Address *felt.Felt
}

Source: devnet.go

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"
	}
 
	devNet := devnet.NewDevNet(devnetURL)
 
	// Get fee token information
	feeToken, err := devNet.FeeToken()
	if err != nil {
		log.Fatal("Failed to get fee token:", err)
	}
 
	fmt.Println("Fee Token Information:")
	fmt.Printf("  Symbol:  %s\n", feeToken.Symbol)
	fmt.Printf("  Address: %s\n", feeToken.Address.String())
}

Use Cases

Query Fee Token Contract

feeToken, err := devNet.FeeToken()
if err != nil {
	log.Fatal(err)
}
 
// Use fee token address for RPC calls
ctx := context.Background()
provider, _ := rpc.NewProvider(ctx, "http://localhost:5050")
 
// Query balance
balance, err := provider.Call(ctx, rpc.FunctionCall{
	ContractAddress:    feeToken.Address,
	EntryPointSelector: balanceOfSelector,
	Calldata:           []*felt.Felt{accountAddress},
}, rpc.WithBlockTag("latest"))

Transfer Fee Tokens

feeToken, err := devNet.FeeToken()
if err != nil {
	log.Fatal(err)
}
 
// Prepare transfer call
transferCall := rpc.FunctionCall{
	ContractAddress:    feeToken.Address,
	EntryPointSelector: transferSelector,
	Calldata: []*felt.Felt{
		recipientAddress,
		amountLow,
		amountHigh,
	},
}
 
// Execute via account
tx, err := account.Execute(ctx, []rpc.FunctionCall{transferCall}, details)

Verify Token Symbol

feeToken, err := devNet.FeeToken()
if err != nil {
	log.Fatal(err)
}
 
if feeToken.Symbol != "ETH" {
	log.Printf("Warning: Unexpected fee token: %s", feeToken.Symbol)
}

Fee Token Details

On DevNet, the fee token is typically:

  • Symbol: ETH
  • Name: Ether
  • Decimals: 18
  • Standard: ERC-20 compatible

The fee token contract address is the same as on Starknet mainnet/testnet for consistency.

Error Handling

feeToken, err := devNet.FeeToken()
if err != nil {
	if strings.Contains(err.Error(), "connection refused") {
		log.Fatal("DevNet is not running. Start it with: starknet-devnet")
	} else {
		log.Fatal("Failed to get fee token:", err)
	}
}
 
if feeToken.Address == nil {
	log.Fatal("Invalid fee token address")
}

Integration with Minting

The fee token is what gets minted when using the Mint() method:

// Get fee token info
feeToken, _ := devNet.FeeToken()
fmt.Printf("Minting %s tokens\n", feeToken.Symbol)
 
// Mint tokens (these will be ETH tokens)
address, _ := utils.HexToFelt("0x123...")
amount := big.NewInt(1000000000000000000) // 1 ETH
 
response, err := devNet.Mint(address, amount)
if err != nil {
	log.Fatal(err)
}
 
fmt.Printf("Minted %s %s\n", response.NewBalance, response.Unit)

Notes

  • Fee token information is static for a DevNet instance
  • The address matches the ETH contract on Starknet networks
  • Used for paying transaction fees on DevNet
  • Can be queried and transferred like any ERC-20 token