HexToFelt
Converts a hexadecimal string to a Felt value.
Function Signature
func HexToFelt(hex string) (*felt.Felt, error)Source: felt.go
Parameters
hex(string): Hexadecimal string (with or without "0x" prefix)
Returns
*felt.Felt: The Felt representationerror: Error if conversion fails
Usage Example
package main
import (
"fmt"
"log"
"github.com/NethermindEth/starknet.go/utils"
)
func main() {
// Convert hex strings to Felt
felt, err := utils.HexToFelt("0x123")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Output: %s\n", felt.String())
// Output: 0x123
// Convert contract address
felt2, err := utils.HexToFelt("0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Output: %s\n", felt2.String())
// Output: 0x7e00d496e324876bbc8531f2d9a82bf154d1a04a50218ee74cdd372f75a551a
}See Also
- Smart Contract Integration shows how to convert contract addresses from hex
- Type Conversions for working with different data formats together

