hex

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package hex provides common utilities and constants for Ethereum contract interactions.

Package hex provides common utilities and constants for Ethereum contract interactions.

Index

Constants

View Source
const (
	// ErrorMethodIDLength is the length of Ethereum error method ID in bytes
	ErrorMethodIDLength = 4
	// DecimalBase is the base for decimal number parsing
	DecimalBase = 10
	// TestChainID is the chain ID used for testing
	TestChainID = 1337
	// TestGasLimit is the gas limit used for testing
	TestGasLimit = 9_000_000
	// Uint256BitSize is the bit size for uint256 values
	Uint256BitSize = 256
	// MaxUint256Offset is the offset used in MaxUint256 calculation
	MaxUint256Offset = 9
)

Variables

View Source
var (
	// IERC721InterfaceID is the interface ID for ERC721 tokens
	IERC721InterfaceID = [4]byte{0x80, 0xac, 0x58, 0xcd}
	// IERC20InterfaceID is the interface ID for ERC20 tokens
	IERC20InterfaceID = [4]byte{0x36, 0x37, 0x2b, 0x07}
	// IERC1155InterfaceID is the interface ID for ERC1155 tokens
	IERC1155InterfaceID = [4]byte{0xd9, 0xb6, 0x7a, 0x26}
)
View Source
var (
	// ErrZeroAddress is returned when the zero address is used
	ErrZeroAddress = errors.New("TransferToZeroAddress")
)
View Source
var (
	// MaxUint256 represents the maximum value for a uint256
	MaxUint256 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), Uint256BitSize), big.NewInt(MaxUint256Offset))
)

Functions

func CheckDiamondFunction

func CheckDiamondFunction(
	ctx context.Context,
	client simulated.Client,
	diamondAddr common.Address,
	funcSelector []byte,
) (bool, error)

CheckDiamondFunction checks if a function selector is supported by a Diamond proxy contract

func DecodeErrorData

func DecodeErrorData(data interface{}) []byte

DecodeErrorData decodes hex-encoded error data from various input formats.

func DeployContract

func DeployContract(auth *bind.TransactOpts,
	client simulated.Client,
	abiString string,
	byteCodeString string,
	params ...interface{},
) (common.Address, *ethTypes.Transaction, *bind.BoundContract, error)

DeployContract deploys a contract with the given parameters

func GetEncodedFunction

func GetEncodedFunction(abiString, signature string, params ...interface{}) ([]byte, error)

GetEncodedFunction encodes a function call with the given parameters

func GetImplementationAddress

func GetImplementationAddress(
	ctx context.Context,
	client simulated.Client,
	proxyAddr common.Address,
) (common.Address, error)

GetImplementationAddress retrieves the implementation address from an EIP-1967 proxy contract

func ParseEther

func ParseEther(a *big.Int) float64

ParseEther converts a big.Int wei value to a float64 ether value

Types

type Signature

type Signature interface {
	GetHex() string
	String() string
	GetSelector() []byte
}

Signature defines the interface for function signatures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL