cmd

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: MIT Imports: 41 Imported by: 0

Documentation

Overview

Copyright © 2025 NAME HERE <EMAIL ADDRESS>

Index

Constants

View Source
const EthGasStationUrl = "https://ethgasstation.info/json/ethgasAPI.json"
View Source
const MulticallContractAddr = "0xcA11bde05977b3631167028862bE2a173976CA11" // See https://github.com/mds1/multicall
View Source
const MulticallFuncSignAggregate = "252dba42" // 4 bytes func signature of `aggregate((address,bytes)[])`
View Source
const MulticallFuncSignGetEthBalance = "4d2301cc" // 4 bytes func signature of `getEthBalance(address)`

Variables

This section is empty.

Functions

func BuildEIP7702Tx added in v1.6.0

func BuildEIP7702Tx(client *ethclient.Client, privateKey *ecdsa.PrivateKey,
	toAddress *common.Address, amount *big.Int, data []byte, delegateTo common.Address,
) (*types.Transaction, error)

BuildEIP7702Tx builds EIP7702 transaction

func BuildEip7702SignedTx added in v1.6.0

func BuildEip7702SignedTx(
	client *ethclient.Client, privateKey *ecdsa.PrivateKey,
	toAddress *common.Address, amount *big.Int, data []byte, sigData []byte, delegateTo common.Address,
) (*types.Transaction, error)

BuildEip7702SignedTx builds signed transaction

func BuildSignedTx added in v1.2.3

func BuildSignedTx(
	client *ethclient.Client, privateKey *ecdsa.PrivateKey, fromAddress,
	toAddress *common.Address, amount, gasPrice *big.Int, data []byte, sigData []byte,
) (*types.Transaction, error)

BuildSignedTx builds signed transaction

func BuildTupleArgData added in v1.2.3

func BuildTupleArgData(typ abi.Type, data []string) (any, error)

BuildTupleArgData build tuple data accepted by abi Pack An example: typ: abi.NewType("tuple", "", []abi.ArgumentMarshaling{{Name: "Field0", Type: "uint256"}, {Name: "Field1", Type: "bool"}}) data: ["15", "true"] return: A dynamically created struct object: { Field0: big.NewInt("15"), Field1: true }

func BuildTupleArrayType added in v1.2.3

func BuildTupleArrayType(tupleType string) (abi.Type, error)

BuildTupleArrayType build tuple array abi.Type An example: tupleType: "(uint256, bool)[5]" return: abi.NewType("tuple[5]", "", []abi.ArgumentMarshaling{{Name: "Field0", Type: "uint256"}, {Name: "Field1", Type: "bool"}})

func BuildTx added in v1.2.3

func BuildTx(client *ethclient.Client, privateKey *ecdsa.PrivateKey, fromAddress,
	toAddress *common.Address, amount, gasPrice *big.Int, data []byte,
) (*types.Transaction, error)

BuildTx builds transaction

func Call

func Call(rpcClient *rpc.Client, toAddress common.Address, data []byte) ([]byte, error)

Call invokes the (constant) contract method.

func Execute

func Execute() error

Execute cobra root command

func GenRawTx

func GenRawTx(signedTx *types.Transaction) (string, error)

GenRawTx return raw tx, a hex string with 0x prefix

func GetFuncSig added in v1.2.3

func GetFuncSig(funcHash string) ([]string, error)

GetFuncSig recover function signature from 4 bytes hash

func GetFuncSigFrom4Byte added in v1.5.0

func GetFuncSigFrom4Byte(funcHash string) ([]string, error)

GetFuncSigFrom4Byte recover function signature from 4 bytes hash from 4byte API For example:

param: "0x8c905368"
return: ["NotEnoughFunds(uint256,uint256)"]

This function uses 4byte API $ curl -X 'GET' 'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x275fb869'

{
 "count": 1,
 "next": null,
 "previous": null,
 "results": [
   {
     "id": 1136703,
     "created_at": "2025-03-22T17:59:30.142145Z",
     "text_signature": "InsufficientSlippage(uint256,uint256)",
     "hex_signature": "0x275fb869",
     "bytes_signature": "'_¸i"
   }
 ]
}

See https://www.4byte.directory/docs/

func GetFuncSigFromOpenchain added in v1.5.0

func GetFuncSigFromOpenchain(funcHash string) ([]string, error)

GetFuncSig recover function signature from 4 bytes hash For example:

param: "0x8c905368"
return: ["NotEnoughFunds(uint256,uint256)"]

This function uses openchain API $ curl -X 'GET' 'https://api.openchain.xyz/signature-database/v1/lookup?function=0x8c905368&filter=true' {"ok":true,"result":{"event":{},"function":{"0x8c905368":[{"name":"NotEnoughFunds(uint256,uint256)","filtered":false}]}}} See https://openchain.xyz/signatures

func GetInitCode added in v1.2.3

func GetInitCode() ([]byte, error)

func GetNonce added in v1.2.3

func GetNonce(sender string) (*big.Int, error)

GetNonce get nonce of AA contract If specified in the parameter, it is used directly. If not specified, it is fetched from function getNonce in EntryPoint

func GetPaymasterAndData added in v1.2.3

func GetPaymasterAndData() ([]byte, error)

func GetRawTx added in v1.5.0

func GetRawTx(rpcClient *rpc.Client, txHash string) (string, error)

GetRawTx get raw tx from rpc node

func GetSender added in v1.2.3

func GetSender() common.Address

func InitGlobalClient

func InitGlobalClient(nodeUrl string)

InitGlobalClient initializes a client that uses the given RPC client.

func MnemonicToPrivateKey added in v1.2.6

func MnemonicToPrivateKey(mnemonic string, derivationPath string) (*ecdsa.PrivateKey, error)

MnemonicToPrivateKey generate private key from mnemonic words

func ParseBigInt added in v1.2.3

func ParseBigInt(input string) (*big.Int, error)

ParseBigInt parses input string to big.Int.

func RecoverPubkey

func RecoverPubkey(v, r, s *big.Int, msg []byte) ([]byte, error)

RecoverPubkey recover public key, returns 65 bytes uncompressed public key

func SendRawTransaction

func SendRawTransaction(rpcClient *rpc.Client, signedTxHexStr string) (*common.Hash, error)

SendRawTransaction broadcast signedTxHexStr and return tx returned by rpc node

func SendSignedTx added in v1.2.3

func SendSignedTx(rpcClient *rpc.Client, signedTx *types.Transaction) (*common.Hash, error)

SendSignedTx broadcast signed tx and return tx returned by rpc node

func Transact

func Transact(rpcClient *rpc.Client, client *ethclient.Client, privateKey *ecdsa.PrivateKey, toAddress *common.Address, amount *big.Int, gasPrice *big.Int, data []byte) (string, error)

Transact invokes the (paid) contract method.

func TransferHelper

func TransferHelper(rcpClient *rpc.Client, client *ethclient.Client, privateKeyHex string, toAddress string, amountInWei *big.Int, gasPrice *big.Int, data []byte) (string, error)

Types

type AbiData

type AbiData struct {
	Inputs []struct {
		Name string `json:"name"`
		Type string `json:"type"`
	} `json:"inputs"`
	Name    string `json:"name"`
	Type    string `json:"type"` // constructor, function, etc.
	Outputs []struct {
		Name string `json:"name"`
		Type string `json:"type"`
	} `json:"outputs"`
}

ABI example: [

 {
     "inputs": [],
     "stateMutability": "nonpayable",
     "type": "constructor"
 },
	{
		"inputs": [
			{
				"internalType": "uint256[]",
				"name": "_a",
				"type": "uint256[]"
			},
			{
				"internalType": "address[]",
				"name": "_addr",
				"type": "address[]"
			}
		],
		"name": "f1",
		"outputs": [],
		"stateMutability": "nonpayable",
		"type": "function"
	},
	{
		"inputs": [],
		"name": "f2",
		"outputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"stateMutability": "view",
		"type": "function"
	},

...... ]

type AbiJSONData

type AbiJSONData struct {
	ABI []AbiData `json:"abi"`
}

type ChainData added in v1.7.0

type ChainData struct {
	Name      string        `json:"name"`
	Chain     string        `json:"chain"`
	ChainId   uint64        `json:"chainId"`
	Rpc       []RpcEndpoint `json:"rpc"`
	ChainSlug string        `json:"chainSlug"`
}

type Client

type Client struct {
	EthClient *ethclient.Client
	RpcClient *rpc.Client
}

type ErrFuncNotFound added in v1.2.3

type ErrFuncNotFound struct {
	FuncName string
}

func (ErrFuncNotFound) Error added in v1.2.3

func (e ErrFuncNotFound) Error() string

type GasStationPrice

type GasStationPrice struct {
	Fast        float64
	Fastest     float64
	SafeLow     float64
	Average     float64
	SafeLowWait float64
	AvgWait     float64
	FastWait    float64
	FastestWait float64
}

GasStationPrice the struct of response of EthGasStationUrl

type RpcEndpoint added in v1.7.0

type RpcEndpoint struct {
	Url          string `json:"url"`
	Tracking     string `json:"tracking"`
	IsOpenSource bool   `json:"isOpenSource,omitempty"`
}

type RpcStatus added in v1.7.0

type RpcStatus struct {
	Url           string
	BlockHeight   *big.Int
	ClientVersion string
	Error         string
	ResponseTime  time.Duration
}

Jump to

Keyboard shortcuts

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