eth

package
v0.0.0-...-96919c3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TokenTypeErc20  = 1
	TokenTypeErc721 = 2
)
View Source
const ERC20InterfaceABI = `` /* 2439-byte string literal not displayed */
View Source
const ERC721InterfaceABI = `` /* 4364-byte string literal not displayed */

Variables

View Source
var BigIntEthGWei = big.NewInt(1e9)

Functions

func CalcEthFee

func CalcEthFee(gasPrice *big.Int, gas int64) int64

func DeployContract

func DeployContract(opts *bind.TransactOpts, backend bind.ContractBackend, jsonAbi string, bytecode string, params ...interface{}) (common.Address, *types.Transaction, error)

func EstimateContractMethodGas

func EstimateContractMethodGas(param TransactBaseParam, backend bind.ContractBackend, contractAddress common.Address, input []byte) (int64, error)

func GweiToWei

func GweiToWei(v int64) *big.Int

func HexToAddress

func HexToAddress(addr string) (common.Address, error)

func HexToHash

func HexToHash(s string) common.Hash

func MakeTransactOpts

func MakeTransactOpts(w *wallet.EthWallet, param TransactBaseParam, gasLimit int64, nonce int64) (*bind.TransactOpts, error)

func SerializeTransaction

func SerializeTransaction(tx *types.Transaction) (string, error)

func SignTx

func TransferEther

func TransferEther(opts *bind.TransactOpts, backend bind.ContractBackend, addressTo common.Address) (*types.Transaction, error)

func WeiToGwei

func WeiToGwei(v *big.Int) int64

Types

type Erc20Contract

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

Erc20Contract tool for contract abi

func NewErc20Contract

func NewErc20Contract(address common.Address, backend bind.ContractBackend) *Erc20Contract

func (*Erc20Contract) Allowance

func (this *Erc20Contract) Allowance(tokenOwner common.Address, spender common.Address) (*big.Int, error)

func (*Erc20Contract) Approve

func (this *Erc20Contract) Approve(opts *bind.TransactOpts, spender common.Address, tokens *big.Int) (*types.Transaction, error)

func (*Erc20Contract) BalanceOf

func (this *Erc20Contract) BalanceOf(tokenOwner common.Address) (*big.Int, error)

func (*Erc20Contract) Decimals

func (this *Erc20Contract) Decimals() (int, error)

func (*Erc20Contract) EstimateApproveGas

func (this *Erc20Contract) EstimateApproveGas(param TransactBaseParam, spender common.Address, tokens *big.Int) (int64, error)

func (*Erc20Contract) EstimateTransferFromGas

func (this *Erc20Contract) EstimateTransferFromGas(param TransactBaseParam, from common.Address, to common.Address, tokens *big.Int) (int64, error)

func (*Erc20Contract) EstimateTransferGas

func (this *Erc20Contract) EstimateTransferGas(param TransactBaseParam, to common.Address, tokens *big.Int) (int64, error)

func (*Erc20Contract) Name

func (this *Erc20Contract) Name() (string, error)

func (*Erc20Contract) Symbol

func (this *Erc20Contract) Symbol() (string, error)

func (*Erc20Contract) TotalSupply

func (this *Erc20Contract) TotalSupply() (*big.Int, error)

func (*Erc20Contract) Transfer

func (this *Erc20Contract) Transfer(opts *bind.TransactOpts, to common.Address, tokens *big.Int) (*types.Transaction, error)

func (*Erc20Contract) TransferFrom

func (this *Erc20Contract) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, tokens *big.Int) (*types.Transaction, error)

type Erc20Meta

type Erc20Meta struct {
	Symbol   string `toml:"symbol" json:"symbol"`
	Address  string `toml:"address" json:"address"`
	Decimals int    `toml:"decimals" json:"decimals"`
}

type Erc721Contract

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

Erc721Contract tool for contract abi

func NewErc721Contract

func NewErc721Contract(address common.Address, backend bind.ContractBackend) *Erc721Contract

func (*Erc721Contract) Approve

func (this *Erc721Contract) Approve(opts *bind.TransactOpts, to common.Address, tokenId *big.Int) (*types.Transaction, error)

func (*Erc721Contract) BalanceOf

func (this *Erc721Contract) BalanceOf(owner common.Address) (*big.Int, error)

IERC721

func (*Erc721Contract) EstimateApproveGas

func (this *Erc721Contract) EstimateApproveGas(param TransactBaseParam, to common.Address, tokenId *big.Int) (int64, error)

func (*Erc721Contract) EstimateSafeTransferFrom2Gas

func (this *Erc721Contract) EstimateSafeTransferFrom2Gas(param TransactBaseParam, from common.Address, to common.Address, tokenId *big.Int, data []byte) (int64, error)

func (*Erc721Contract) EstimateSafeTransferFromGas

func (this *Erc721Contract) EstimateSafeTransferFromGas(param TransactBaseParam, from common.Address, to common.Address, tokenId *big.Int) (int64, error)

EstimateGas

func (*Erc721Contract) EstimateSetApprovalForAllGas

func (this *Erc721Contract) EstimateSetApprovalForAllGas(param TransactBaseParam, operator common.Address, approved bool) (int64, error)

func (*Erc721Contract) EstimateTransferFromGas

func (this *Erc721Contract) EstimateTransferFromGas(param TransactBaseParam, from common.Address, to common.Address, tokenId *big.Int) (int64, error)

func (*Erc721Contract) GetApproved

func (this *Erc721Contract) GetApproved(tokenId *big.Int) (common.Address, error)

func (*Erc721Contract) IsApprovedForAll

func (this *Erc721Contract) IsApprovedForAll(owner common.Address, operator common.Address) (bool, error)

func (*Erc721Contract) Name

func (this *Erc721Contract) Name() (string, error)

IERC721Metadata

func (*Erc721Contract) OwnerOf

func (this *Erc721Contract) OwnerOf(tokenId *big.Int) (common.Address, error)

func (*Erc721Contract) SafeTransferFrom

func (this *Erc721Contract) SafeTransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error)

func (*Erc721Contract) SafeTransferFrom2

func (this *Erc721Contract) SafeTransferFrom2(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int, data []byte) (*types.Transaction, error)

func (*Erc721Contract) SetApprovalForAll

func (this *Erc721Contract) SetApprovalForAll(opts *bind.TransactOpts, operator common.Address, approved bool) (*types.Transaction, error)

func (*Erc721Contract) SupportsInterface

func (this *Erc721Contract) SupportsInterface(interfaceId [4]byte) (bool, error)

IERC165

func (*Erc721Contract) Symbol

func (this *Erc721Contract) Symbol() (string, error)

func (*Erc721Contract) TokenByIndex

func (this *Erc721Contract) TokenByIndex(index *big.Int) (*big.Int, error)

func (*Erc721Contract) TokenOfOwnerByIndex

func (this *Erc721Contract) TokenOfOwnerByIndex(owner common.Address, index *big.Int) (*big.Int, error)

func (*Erc721Contract) TokenURI

func (this *Erc721Contract) TokenURI(tokenId *big.Int) (string, error)

func (*Erc721Contract) TotalSupply

func (this *Erc721Contract) TotalSupply() (*big.Int, error)

IERC721Enumerable

func (*Erc721Contract) TransferFrom

func (this *Erc721Contract) TransferFrom(opts *bind.TransactOpts, from common.Address, to common.Address, tokenId *big.Int) (*types.Transaction, error)

type EthClient

type EthClient struct {
	RpcClient *ethclient.Client
	// contains filtered or unexported fields
}

func NewEthClient

func NewEthClient(URL string) (*EthClient, error)

func (*EthClient) GetTransactionCountByNumber

func (this *EthClient) GetTransactionCountByNumber(ctx context.Context, blockNumber int64) (uint, error)

func (*EthClient) SendRawTransaction

func (this *EthClient) SendRawTransaction(ctx context.Context, signedHex string) (string, error)

func (*EthClient) SetHeader

func (this *EthClient) SetHeader(key, value string)

func (*EthClient) TransactionByHash

func (this *EthClient) TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, from *common.Address, blockNumber *big.Int, err error)

type TransactBaseParam

type TransactBaseParam struct {
	From      common.Address
	EthValue  *big.Int
	GasPrice  *big.Int
	GasFeeCap *big.Int
	GasTipCap *big.Int
	BaseFee   *big.Int
}

func (*TransactBaseParam) EnsureGasPrice

func (this *TransactBaseParam) EnsureGasPrice(backend bind.ContractBackend) error

func (*TransactBaseParam) GetGasPrice

func (this *TransactBaseParam) GetGasPrice() *big.Int

type TransferEvent

type TransferEvent struct {
	Txid            string
	BlockNumber     int64
	TokenType       int
	ContractAddress string
	From            string
	To              string
	Value           string
}

func FilterTransferLog

func FilterTransferLog(cli *ethclient.Client, fromBlock int64, toBlock int64, contractAddresses []common.Address) ([]*TransferEvent, error)

Jump to

Keyboard shortcuts

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