evmutils

package module
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 7 Imported by: 0

README

evm-utils

ethereum生态的常用工具,如钱包生成、账户余额查询、转账等等

使用方式

具体使用方式,先看根目录的evmutils_test.go吧,后面有空了再写

** 关于model/contract/中的使用说明

合约交互不比简单转账,它是有参数的,而且参数的编码也要严格遵守规范,go-ethereum自带的abigen可以根据合约的ABI文件,自动生成对应的Go文件。
go-ethereum相关程序官方下载入口

举例:
假设要获取erc20的基本操作流程
OpenZeppelin库 下载接口文件,然后放到Remix里编译,拷贝出ABI文件
保存的ABI文件名是IERC20.json
运行命令

abigen --abi IERC20.json --type ERC20 --pkg erc20 --out erc20.go

之后进一步操作erc20的golang代码即可。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvmClient added in v1.2.13

type EvmClient struct {
	RpcUrl string
	// contains filtered or unexported fields
}

func NewEthClient

func NewEthClient(rpcUrl string, timeout int64) *EvmClient

NewEthClient

@Description: if rpcUrl and timeout is empty,you can‘t connect the node,but you can use the function about wallet
@param rpcUrl
@param timeout
@return *EvmClient

func NewSimpleEthClient

func NewSimpleEthClient() *EvmClient

NewSimpleEthClient

@Description: not support connect to the node
@return *EvmClient

func (*EvmClient) AccountByMnemonic added in v1.2.13

func (o *EvmClient) AccountByMnemonic() (account *model.Account, err error)

func (*EvmClient) AccountGenKeystore added in v1.2.13

func (o *EvmClient) AccountGenKeystore(privateKey, pwd, path string) (address string, err error)

func (*EvmClient) AccountInfoByMnemonic added in v1.2.13

func (o *EvmClient) AccountInfoByMnemonic(mnemonic string) (account *model.Account, err error)

AccountInfoByMnemonic

@Description:
@receiver o
@param mnemonic
@return account
@return err

func (*EvmClient) AccountWithPrivateKey added in v1.2.13

func (o *EvmClient) AccountWithPrivateKey(privateKey string) (account *model.Account, err error)

func (*EvmClient) Chain added in v1.2.13

func (o *EvmClient) Chain() (*model.Chain, error)

func (*EvmClient) LatestBlockNumber added in v1.2.13

func (o *EvmClient) LatestBlockNumber() (uint64, error)

LatestBlockNumber

@Description: 获取最新块
@receiver o
@return uint64
@return error

func (*EvmClient) MetamaskSignLogin added in v1.2.13

func (o *EvmClient) MetamaskSignLogin(message, privateKey string) (string, error)

MetamaskSignLogin

@Description: metamask sign login
@receiver o
@param message
@param privateKey
@return string
@return error

func (*EvmClient) Nonce added in v1.2.13

func (o *EvmClient) Nonce(address string) (nonce uint64, err error)

func (*EvmClient) SignEip721 added in v1.2.13

func (o *EvmClient) SignEip721(privateKey string, typedData *apitypes.TypedData) (string, error)

SignEip721

@Description: eip721 sign
@receiver o
@param privateKey
@param typedData
@return string
@return error

func (*EvmClient) TokenBalanceOf added in v1.2.13

func (o *EvmClient) TokenBalanceOf(address string) (balance string, err error)

func (*EvmClient) TokenErc20BalanceOf added in v1.2.13

func (o *EvmClient) TokenErc20BalanceOf(address, contractAddress string, opts *bind.CallOpts) (balance string, err error)

TokenErc20BalanceOf

@Description: erc20 balance
@receiver o
@param address user's account address
@param contractAddress erc20 address
@opts options
@return balance
@return err

func (*EvmClient) TokenEstimateGasLimit added in v1.2.13

func (o *EvmClient) TokenEstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string, data []byte) (balance string, err error)

TokenEstimateGasLimit

@Description: 估算gas ,如果是合约地址,data肯定不得为空
@receiver o
@param fromAddress
@param receiverAddress
@param gasPrice
@param amount
@param data
@return balance
@return err

func (*EvmClient) TokenTransfer added in v1.2.13

func (o *EvmClient) TokenTransfer(privateKey, nonce, gasPrice, gasLimit, maxPriorityFeePerGas, value, to, data string) (hash string, err error)

func (*EvmClient) TxByBlockNumber added in v1.2.13

func (o *EvmClient) TxByBlockNumber(number uint64) ([]model.Transaction, error)

TxByBlockNumber

@Description: get all tx by block number
@receiver o
@param number
@return []model.Transaction
@return error

func (*EvmClient) TxByHash added in v1.2.13

func (o *EvmClient) TxByHash(hash string) (*model.Transaction, error)

TxByHash

@Description: 根据hash获取交易回执
@receiver o
@param hash
@return *types.Receipt
@return error

func (*EvmClient) TxIsPending added in v1.2.13

func (o *EvmClient) TxIsPending(hash string) (bool, error)

TxIsPending

@Description: is pending
@receiver o
@param hash
@return bool
@return error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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