etherkit

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ZeroAddress = "0x0000000000000000000000000000000000000000"
	EAddress    = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
)
View Source
const ZeroHash = "0x0000000000000000000000000000000000000000000000000000000000000000"

Variables

This section is empty.

Functions

func BuildContractInputData

func BuildContractInputData(contract abi.ABI, name string, args ...interface{}) ([]byte, error)

BuildContractInputData 构建合约的input data

func BuildPrivateKeyFromHex

func BuildPrivateKeyFromHex(privateKeyHex string) (*ecdsa.PrivateKey, error)

BuildPrivateKeyFromHex 从字符串私钥构建私钥对象

func BuildPrivateKeyFromMnemonic

func BuildPrivateKeyFromMnemonic(mnemonic string, accountId uint32) (*ecdsa.PrivateKey, error)

BuildPrivateKeyFromMnemonic 从助记词获得私钥

func DecodeRawTxHex

func DecodeRawTxHex(rawTx string) (*types.Transaction, error)

DecodeRawTxHex 解析rawTx

func GeneratePrivateKey

func GeneratePrivateKey() (*ecdsa.PrivateKey, error)

GeneratePrivateKey 创建私钥

func GetABI

func GetABI(abiStr string) (abi.ABI, error)

GetABI 从abi字符串中获得ABI对象

func GetContractMethodId

func GetContractMethodId(method string) string

GetContractMethodId 获得合约的methodId 参数method,如:transfer(address,uint256)

func GetEventTopic

func GetEventTopic(event string) string

GetEventTopic 获得事件的topic。event字符串如:transfer(address,uint256)

func GetHexPrivateKey

func GetHexPrivateKey(privateKey *ecdsa.PrivateKey) string

GetHexPrivateKey 创建十六进制的私钥(不以0x开头)

func GetHexPublicKey

func GetHexPublicKey(privateKey *ecdsa.PrivateKey) string

GetHexPublicKey 从私钥中获得十六进制的公钥(不以0x和04开头)

func GetMaxUint256 added in v0.0.5

func GetMaxUint256() *big.Int

GetMaxUint256 获得合约中MaxUint256

func IsValidAddress

func IsValidAddress(iAddress interface{}) bool

IsValidAddress 验证是否是十六进制地址

func NewTx

func NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error)

NewTx 新建一个tx

func NewTxWithHexData

func NewTxWithHexData(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, hexData string) (*types.Transaction, error)

NewTxWithHexData 基于hexData构建一个Tx

func PrivateKeyToAddress

func PrivateKeyToAddress(privateKey *ecdsa.PrivateKey) common.Address

PrivateKeyToAddress 从私钥中获得地址

func PublicKeyBytesToAddress

func PublicKeyBytesToAddress(publicKey []byte) common.Address

PublicKeyBytesToAddress 公钥到地址

func ToDecimal

func ToDecimal(iValue interface{}, decimals int) decimal.Decimal

ToDecimal wei to decimals

func ToWei

func ToWei(iAmount interface{}, decimals int) *big.Int

ToWei decimals to wei

func VerifySignature

func VerifySignature(address string, data, signature []byte) bool

VerifySignature 验证签名 address: 用于签名的地址 digestHash: 用于验证的原始数据 signature: 需要进行验证的签名数据

Types

type EtherProvider added in v0.0.6

type EtherProvider interface {
	GetEthClient() *ethclient.Client
	GetRpcClient() *rpc.Client
	Close()
	GetNetworkID() (*big.Int, error)
	GetChainID() (*big.Int, error)
	GetBlockByHash(hash common.Hash) (*types.Block, error)
	GetBlockByNumber(number *big.Int) (*types.Block, error)
	GetBlockNumber() (uint64, error)
	GetSuggestGasPrice() (*big.Int, error)
	GetTransactionByHash(hash common.Hash) (tx *types.Transaction, isPending bool, err error)
	GetTransactionReceipt(txHash common.Hash) (*types.Receipt, error)
	GetContractBytecode(address common.Address) (string, error)
	IsContractAddress(address common.Address) (bool, error)
	EstimateGas(from, to common.Address, nonce uint64, gasPrice, value *big.Int, data []byte) (uint64, error)
	GetFromAddress(tx *types.Transaction) (common.Address, error)
}

EtherProvider 需要通过链上查询的,但是不需要账户的

type EtherSigner added in v0.0.6

type EtherSigner interface {
	GetAddress() common.Address
	GetPrivateKey() *ecdsa.PrivateKey
}

EtherSigner ETH账户

type EtherWallet added in v0.0.5

type EtherWallet interface {
	GetEthSigner() EtherSigner
	GetEthProvider() EtherProvider
	GetClient() *ethclient.Client
	GetAddress() common.Address
	CloseWallet()
	GetNonce() (uint64, error)
	GetBalance() (*big.Int, error)
	NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error)
	SendTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (common.Hash, error)
	NewTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (*types.Transaction, error)
	SendTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (common.Hash, error)
	BuildTxOpts(value, nonce, gasPrice *big.Int) (*bind.TransactOpts, error)
	SignTx(tx *types.Transaction) (*types.Transaction, error)
	SendSignedTx(signedTx *types.Transaction) (common.Hash, error)
	Signature(data []byte) ([]byte, error)
	CallContract(contractAddress common.Address, contractAbi abi.ABI, functionName string, params ...interface{}) ([]interface{}, error)
}

EtherWallet 钱包信息

type Provider added in v0.0.6

type Provider struct {
	// contains filtered or unexported fields
}

func NewProvider added in v0.0.8

func NewProvider(rawUrl string) (*Provider, error)

func NewProviderWithChainId added in v0.0.8

func NewProviderWithChainId(rawUrl string, chainId int64) (*Provider, error)

func (*Provider) Close added in v0.0.6

func (p *Provider) Close()

Close 关闭ethClient客户端和rpcClient客户端

func (*Provider) EstimateGas added in v0.0.6

func (p *Provider) EstimateGas(from, to common.Address, nonce uint64, gasPrice, value *big.Int, data []byte) (uint64, error)

EstimateGas 预估手续费

func (*Provider) GetBlockByHash added in v0.0.6

func (p *Provider) GetBlockByHash(blkHash common.Hash) (*types.Block, error)

GetBlockByHash 根据区块Hash获得区块信息

func (*Provider) GetBlockByNumber added in v0.0.6

func (p *Provider) GetBlockByNumber(number *big.Int) (*types.Block, error)

GetBlockByNumber 根据区块号获得区块信息

func (*Provider) GetBlockNumber added in v0.0.6

func (p *Provider) GetBlockNumber() (uint64, error)

GetBlockNumber 获得最新区块

func (*Provider) GetChainID added in v0.0.6

func (p *Provider) GetChainID() (*big.Int, error)

GetChainID 获得ChainId

func (*Provider) GetContractBytecode added in v0.0.6

func (p *Provider) GetContractBytecode(address common.Address) (string, error)

GetContractBytecode 根据合约地址获得bytecode

func (*Provider) GetEthClient added in v0.0.6

func (p *Provider) GetEthClient() *ethclient.Client

GetEthClient 获得ethClient客户端

func (*Provider) GetFromAddress added in v0.0.6

func (p *Provider) GetFromAddress(tx *types.Transaction) (common.Address, error)

GetFromAddress 获得交易的fromAddress

func (*Provider) GetNetworkID added in v0.0.6

func (p *Provider) GetNetworkID() (*big.Int, error)

GetNetworkID 获得NetworkId

func (*Provider) GetRpcClient added in v0.0.6

func (p *Provider) GetRpcClient() *rpc.Client

GetRpcClient 获得rpcClient客户端

func (*Provider) GetSuggestGasPrice added in v0.0.6

func (p *Provider) GetSuggestGasPrice() (*big.Int, error)

GetSuggestGasPrice 获得建议的Gas

func (*Provider) GetTransactionByHash added in v0.0.6

func (p *Provider) GetTransactionByHash(txHash common.Hash) (tx *types.Transaction, isPending bool, err error)

GetTransactionByHash 根据txHash获得交易信息

func (*Provider) GetTransactionReceipt added in v0.0.6

func (p *Provider) GetTransactionReceipt(txHash common.Hash) (*types.Receipt, error)

GetTransactionReceipt 根据txHash获得交易Receipt

func (*Provider) IsContractAddress added in v0.0.6

func (p *Provider) IsContractAddress(address common.Address) (bool, error)

IsContractAddress 是否是合约地址。

type Signer added in v0.0.6

type Signer struct {
	// contains filtered or unexported fields
}

func NewSigner added in v0.0.8

func NewSigner() (*Signer, error)

NewSigner 创建一个默认的账号信息

func NewSignerFromHexPrivateKey added in v0.0.8

func NewSignerFromHexPrivateKey(hexPk string) (*Signer, error)

NewSignerFromHexPrivateKey 使用私钥创建一个账号信息

func NewSignerFromMnemonic added in v0.0.8

func NewSignerFromMnemonic(mnemonic string) (*Signer, error)

NewSignerFromMnemonic 使用助记词创建一个账号信息

func NewSignerFromMnemonicAndAccountId added in v0.0.8

func NewSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32) (*Signer, error)

NewSignerFromMnemonicAndAccountId 使用助记词创建一个账号信息

func NewSignerFromPrivateKey added in v0.0.8

func NewSignerFromPrivateKey(pk *ecdsa.PrivateKey) (*Signer, error)

NewSignerFromPrivateKey 使用私钥创建一个账号信息

func NewSignerFromRawPrivateKey added in v0.0.8

func NewSignerFromRawPrivateKey(rawPk []byte) (*Signer, error)

NewSignerFromRawPrivateKey 使用私钥创建一个账号信息

func (*Signer) GetAddress added in v0.0.6

func (s *Signer) GetAddress() common.Address

GetAddress 获得地址

func (*Signer) GetPrivateKey added in v0.0.6

func (s *Signer) GetPrivateKey() *ecdsa.PrivateKey

GetPrivateKey 获得私钥

type Wallet added in v0.0.6

type Wallet struct {
	// contains filtered or unexported fields
}

func NewWallet

func NewWallet(hexPk string, rawUrl string) (*Wallet, error)

NewWallet 新建一个Wallet

func NewWallet1 added in v0.0.8

func NewWallet1(es EtherSigner, ep EtherProvider) (*Wallet, error)

NewWallet1 新建Wallet

func (*Wallet) BuildTxOpts added in v0.0.6

func (w *Wallet) BuildTxOpts(value, nonce, gasPrice *big.Int) (*bind.TransactOpts, error)

BuildTxOpts 构建交易的选项

func (*Wallet) CallContract added in v0.0.6

func (w *Wallet) CallContract(contractAddress common.Address, contractAbi abi.ABI, functionName string, params ...interface{}) ([]interface{}, error)

CallContract 调用合约的方法,无需创建交易

func (*Wallet) CloseWallet added in v0.0.6

func (w *Wallet) CloseWallet()

CloseWallet 关闭Wallet

func (*Wallet) GetAddress added in v0.0.6

func (w *Wallet) GetAddress() common.Address

GetAddress 获得地址

func (*Wallet) GetBalance added in v0.0.6

func (w *Wallet) GetBalance() (*big.Int, error)

GetBalance 获得本位币的约

func (*Wallet) GetClient added in v0.0.6

func (w *Wallet) GetClient() *ethclient.Client

func (*Wallet) GetEthProvider added in v0.0.6

func (w *Wallet) GetEthProvider() EtherProvider

GetEthProvider 获得EthProvider

func (*Wallet) GetEthSigner added in v0.0.6

func (w *Wallet) GetEthSigner() EtherSigner

GetEthSigner 获得EthSinger

func (*Wallet) GetNonce added in v0.0.6

func (w *Wallet) GetNonce() (uint64, error)

GetNonce 获得nonce

func (*Wallet) NewTx added in v0.0.6

func (w *Wallet) NewTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (*types.Transaction, error)

NewTx 构建一笔交易。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。

func (*Wallet) NewTxWithHexInput added in v0.0.6

func (w *Wallet) NewTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (*types.Transaction, error)

NewTxWithHexInput 构建一笔交易,使用0x开头的input。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。

func (*Wallet) SendSignedTx added in v0.0.6

func (w *Wallet) SendSignedTx(signedTx *types.Transaction) (common.Hash, error)

SendSignedTx 发送签名后的Tx

func (*Wallet) SendTx added in v0.0.6

func (w *Wallet) SendTx(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, data []byte) (common.Hash, error)

SendTx 发送交易。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。

func (*Wallet) SendTxWithHexInput added in v0.0.6

func (w *Wallet) SendTxWithHexInput(to common.Address, nonce, gasLimit uint64, gasPrice, value *big.Int, input string) (common.Hash, error)

SendTxWithHexInput 发送一笔交易,使用0x开头的input。nonce传0表示字段计算;gasLimit传0表示字段计算;gasPrice穿nil或者big.NewInt(0)表示gasPrice自动计算。

func (*Wallet) SignTx added in v0.0.6

func (w *Wallet) SignTx(tx *types.Transaction) (*types.Transaction, error)

SignTx 对交易进行签名

func (*Wallet) Signature added in v0.0.6

func (w *Wallet) Signature(data []byte) ([]byte, error)

Signature 生成一个签名

Jump to

Keyboard shortcuts

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