utils

package
v0.0.0-...-1c25370 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NativeTokenDecimals = 18
)

Variables

View Source
var (
	BscForkClient, _  = rpc.DialContext(context.Background(), "https://rpc.phalcon.blocksec.com/rpc_25d3496386cd49d79e0055b9708af0a6")
	ETHClient, _      = rpc.DialContext(context.Background(), "https://eth-mainnet.g.alchemy.com/v2/qUt8liQq0Kh5rGm9VGGfLfSNLFuONhm3")
	BscClient, _      = rpc.DialContext(context.Background(), "https://binance.llamarpc.com")
	ArbitrumClient, _ = rpc.DialContext(context.Background(), "https://arb-mainnet.g.alchemy.com/v2/vJawUvyo1NE02qYepEe2n_AtjrX_gF5q")
	BaseClient, _     = rpc.DialContext(context.Background(), "https://base-mainnet.g.alchemy.com/v2/7XuVI7nNb8mJFfDc_HlEOiFPVNz4lKAz")
	MerlinClient, _   = rpc.DialContext(context.Background(), "https://rpc.merlinchain.io/api")
	Sender            = common.HexToAddress("0xba46dd807DD7A5bBe2eE80b6D0516A088223C574")
	EthForkClient, _  = rpc.DialContext(context.Background(), "https://rpc-dev.phalcon.blocksec.com/rpc_672bb0b921e64497a127b102e9d35db6")
	MantaClient, _    = rpc.DialContext(context.Background(), "https://pacific-rpc.manta.network/http")
)
View Source
var (
	ErrNoData = errors.New("no data")
)

Functions

func CalcGasCost

func CalcGasCost(gasLimit uint64, gasPrice *big.Int) *big.Int

CalcGasCost calculate gas cost given gas limit (units) and gas price (wei)

func CalculateInterfaceId

func CalculateInterfaceId(contractABI string) []byte

func Call

func Call(ctx context.Context, c *rpc.Client, contract string, method abi.Method) (any, error)

func CallWithInput

func CallWithInput(ctx context.Context, c *rpc.Client, contract, methodName string, abiO *abi.ABI, args ...any) ([]any, error)

func CodeAt

func CodeAt(ctx context.Context, c *rpc.Client, contract string) (string, error)

func CreateTransaction

func CreateTransaction(ctx context.Context, client *ethclient.Client, sender, to string, value, gas *big.Int, gasLimit uint64, input string) (*types.Transaction, error)

func DecodeABI

func DecodeABI(abiStr string) (*abi.ABI, error)

func GetBalance

func GetBalance(ctx context.Context, c *rpc.Client, address string) (string, error)

func GetBalanceWithDecimals

func GetBalanceWithDecimals(ctx context.Context, c *rpc.Client, address string) (decimal.Decimal, error)

func Hex2Bytes

func Hex2Bytes(str string) []byte

func IsERC721

func IsERC721()

IsERC721 supportsInterface(0x80ac58cd)是否返回true

func IsValidAddress

func IsValidAddress(addr any) bool

IsValidAddress validate hex address

func IsZeroAddress

func IsZeroAddress(addr any) bool

IsZeroAddress validate if it's a 0 address

func ParseStorageLayout

func ParseStorageLayout(ctx context.Context, c *rpc.Client, contract, storage string) (any, error)

func ParseVyPerStorage

func ParseVyPerStorage(ctx context.Context, c *rpc.Client, contract, abiStr string, storageLayout map[string]types.VyPerStorage) ([]types.ContractVariable, error)

func ParseVyPerStorageLayout

func ParseVyPerStorageLayout(ctx context.Context, c *rpc.Client, contract, storage, abiStr string) (any, error)

func PublicKeyBytesToAddress

func PublicKeyBytesToAddress(publicKey []byte) common.Address

PublicKeyBytesToAddress zero address return if key is invalid

func RemoveZeroHex

func RemoveZeroHex(s string) []byte

RemoveZeroHex delete the 0x from the front

func SignTransaction

func SignTransaction(tx *types.Transaction, privateKeyHex string, chainID *big.Int) (*types.Transaction, error)

func StorageAt

func StorageAt(ctx context.Context, c *rpc.Client, contract string, slot common.Hash) ([]byte, error)

func SubscribeContractEvents

func SubscribeContractEvents(ctx context.Context, client *ethclient.Client, contractAddress common.Address, fromBlock, toBlock *big.Int, topics []string) error

func ToDecimal

func ToDecimal(val any, decimals int) decimal.Decimal

ToDecimal wei to decimals

func ToWei

func ToWei(value any, decimals int) *big.Int

ToWei decimals to wei

func Withdraw

func Withdraw(ctx context.Context, c *rpc.Client, from, to, privateKeyHex string) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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