StrToHex
Converts a string to its hexadecimal representation.
Function Signature
func StrToHex(str string) stringSource: keccak.go
Parameters
str(string): ASCII string to convert
Returns
string: Hexadecimal string with "0x" prefix
Usage Example
package main
import (
"fmt"
"github.com/NethermindEth/starknet.go/utils"
)
func main() {
// Encode "Hello"
hex := utils.StrToHex("Hello")
fmt.Printf("Hello = %s\n", hex)
// Output: 0x48656c6c6f
// Encode "World"
hex2 := utils.StrToHex("World")
fmt.Printf("World = %s\n", hex2)
// Output: 0x576f726c64
// Encode "Starknet"
hex3 := utils.StrToHex("Starknet")
fmt.Printf("Starknet = %s\n", hex3)
// Output: 0x537461726b6e6574
}Use Cases
- Encoding contract names.
- Preparing token symbols.
- Converting short strings for contract calls.
See Also
- Type Conversions shows string encoding patterns

