cmd

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 38 Imported by: 0

Documentation

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 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 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 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)

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 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

Jump to

Keyboard shortcuts

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