eth

package
v0.0.0-...-3f3ae68 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ERC20  交易method
	ERC20_METHOD_TRANSFER = "transfer"
	ERC20_METHOD_APPROVE  = "approve"
)
View Source
const (
	DEFAULT_CONTRACT_GAS_LIMIT = "63000"
	DEFAULT_ETH_GAS_LIMIT      = "21000"
	// 当前网络 standard gas price
	DEFAULT_ETH_GAS_PRICE = "20000000000"
)

默认gas limit估算失败后,21000 * 3 = 63000

View Source
const (
	NetworkNameEthereum  = "ethereum"
	NetworkNameBSC       = "binance_smart_chain"
	NetworkNamePolygon   = "polygon"
	NetworkNameArbitrum  = "arbitrum"
	NetworkNameOptimism  = "optimism"
	NetworkNameAvalanche = "avalanche"

	TagCollectible = "collectible"
)
View Source
const (
	RPAMethodCreate = "create"
	RPAMethodOpen   = "open"
	RPAMethodClose  = "close"
)
View Source
const (
	// 合约 ABI json文件,查询ERC20 相关代币信息需要使用 ABI 文件
	Erc20AbiStr = `` /* 4592-byte string literal not displayed */
)
View Source
const RedPacketABI = `` /* 4896-byte string literal not displayed */

Variables

View Source
var Rpcs = RpcConfig{
	// contains filtered or unexported fields
}

Functions

func DecodeAddressToPublicKey

func DecodeAddressToPublicKey(address string) (string, error)

Warning: eth cannot support decode address to public key

func DecodeContractParams

func DecodeContractParams(abiString string, data []byte) (string, []interface{}, error)

func EncodeContractData

func EncodeContractData(abiString, method string, params ...interface{}) ([]byte, error)

func EncodeErc20Approve

func EncodeErc20Approve(spender string, amount *big.Int) ([]byte, error)

func EncodeErc20Transfer

func EncodeErc20Transfer(toAddress, amount string) ([]byte, error)

Encode erc20 transfer data

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey string) (string, error)

func GetChainId

func GetChainId(e *EthChain) (string, error)

获取链ID

func IsValidAddress

func IsValidAddress(address string) bool

Check if address is 40 hexadecimal characters

func IsValidEIP55Address

func IsValidEIP55Address(address string) bool

It will check based on eip55 rules

func IsValidSignature

func IsValidSignature(publicKey, msg, signature []byte) bool

func PrivateKeyToAddress

func PrivateKeyToAddress(privateKey string) (string, error)

私钥转地址

func SignHashForMsg

func SignHashForMsg(data string) []byte

以太坊的 hash 专门在数据前面加上了一段话

func ToChecksumAddress

func ToChecksumAddress(address string) string

ToChecksumAddress 将以太坊地址从不区分大小写转换为区分大小写

func TransformEIP55Address

func TransformEIP55Address(address string) string

func VerifySignature

func VerifySignature(pubkey, message, signedMsg string) bool

Types

type Account

type Account struct {
	*Util
	// contains filtered or unexported fields
}

func AccountWithPrivateKey

func AccountWithPrivateKey(privatekey string) (*Account, error)

func AsEthereumAccount

func AsEthereumAccount(account base.Account) *Account

func EthAccountWithPrivateKey

func EthAccountWithPrivateKey(privateKey string) (*Account, error)

We cannot use name `NewAccountWithPrivateKey`, because android not support.

func NewAccountWithMnemonic

func NewAccountWithMnemonic(mnemonic string) (*Account, error)

func (*Account) Address

func (a *Account) Address() string

The ethereum address is same as public key in coming

func (*Account) PrivateKey

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

Is deocde from address @return publicKey data

func (*Account) PublicKeyHex

func (a *Account) PublicKeyHex() string

The ethereum public key is same as address in coming @return publicKey string that will start with 0x.

func (*Account) Sign

func (a *Account) Sign(message []byte, password string) ([]byte, error)

签名消息

func (*Account) SignHash

func (a *Account) SignHash(hash []byte) ([]byte, error)

对哈希进行签名

func (*Account) SignHex

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

type BuildTxResult

type BuildTxResult struct {
	SignedTx *types.Transaction
	TxHex    string
}

type CallMethodOpts

type CallMethodOpts struct {
	Nonce                int64
	Value                string
	GasPrice             string // MaxFeePerGas
	GasLimit             string
	IsPredictError       bool
	MaxPriorityFeePerGas string
}

type CallMethodOptsBigInt

type CallMethodOptsBigInt struct {
	Nonce                uint64
	Value                *big.Int
	GasPrice             *big.Int // MaxFeePerGas
	GasLimit             uint64
	IsPredictError       bool
	MaxPriorityFeePerGas *big.Int
}

func OptsTobigInt

func OptsTobigInt(opts *CallMethodOpts) *CallMethodOptsBigInt

将MethodOpts 进行转化,由于端的限制,只能传入string字符

type CallMsg

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

CallMsg contains parameters for contract calls.

func NewCallMsg

func NewCallMsg() *CallMsg

NewCallMsg creates an empty contract call parameter list.

func (*CallMsg) GetData

func (msg *CallMsg) GetData() []byte

func (*CallMsg) GetDataHex

func (msg *CallMsg) GetDataHex() string

func (*CallMsg) GetFrom

func (msg *CallMsg) GetFrom() string

func (*CallMsg) GetGasLimit

func (msg *CallMsg) GetGasLimit() string

func (*CallMsg) GetGasPrice

func (msg *CallMsg) GetGasPrice() string

func (*CallMsg) GetTo

func (msg *CallMsg) GetTo() string

func (*CallMsg) GetValue

func (msg *CallMsg) GetValue() string

func (*CallMsg) SetData

func (msg *CallMsg) SetData(data []byte)

func (*CallMsg) SetDataHex

func (msg *CallMsg) SetDataHex(hex string)

func (*CallMsg) SetFrom

func (msg *CallMsg) SetFrom(address string)

func (*CallMsg) SetGasLimit

func (msg *CallMsg) SetGasLimit(gas string)

func (*CallMsg) SetGasPrice

func (msg *CallMsg) SetGasPrice(price string)

func (*CallMsg) SetTo

func (msg *CallMsg) SetTo(address string)

func (*CallMsg) SetValue

func (msg *CallMsg) SetValue(value string)

Set amount with decimal number

func (*CallMsg) SetValueHex

func (msg *CallMsg) SetValueHex(hex string)

Set amount with hexadecimal number

func (*CallMsg) TransferToTransaction

func (msg *CallMsg) TransferToTransaction() *Transaction

type Chain

type Chain struct {
	RpcUrl string
}

func NewChainWithRpc

func NewChainWithRpc(rpcUrl string) *Chain

func (*Chain) BalanceOfAccount

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)

func (*Chain) BalanceOfPublicKey

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Chain) BatchErc20TokenBalance

func (c *Chain) BatchErc20TokenBalance(contractList []string, address string) ([]string, error)

批量请求代币余额 @param contractList 批量查询的代币的合约地址数组 @param address 用户的钱包地址 @return 余额数组,顺序与传入的 contractList 是保持一致的 @throw 如果任意一个代币请求余额出错时,会抛出错误

func (*Chain) BatchFetchErc20TokenBalance

func (c *Chain) BatchFetchErc20TokenBalance(contractListString, address string) (string, error)

SDK 批量请求代币余额,因为 golang 导出的方法不支持数组,因此传参和返回都只能用字符串 @param contractListString 批量查询的代币的合约地址字符串,用逗号隔开,例如: "add1,add2,add3" @param address 用户的钱包地址 @return 余额列表,顺序与传入合约顺序是保持一致的,例如: "b1,b2,b3" @throw 如果任意一个代币请求余额出错时,会抛出错误

func (*Chain) BatchFetchTransactionStatus

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

Batch fetch the transaction status, the hash list and the return value, which can only be passed as strings separated by "," @param hashListString The hash of the transactions to be queried in batches, a string concatenated with ",": "hash1,hash2,hash3" @return Batch transaction status, its order is consistent with hashListString: "status1,status2,status3"

func (*Chain) BuildTransferTx

func (c *Chain) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) BuildTransferTxWithAccount

func (c *Chain) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) CallContract

func (c *Chain) CallContract(msg *CallMsg, blockNumber int64) (string, error)

call eth_call method @param blockNumber Especially -2 is the latest block, -1 is pending block.

func (*Chain) ChainId

func (c *Chain) ChainId() (string, error)

func (*Chain) EnsureApprovedTokens

func (c *Chain) EnsureApprovedTokens(account *Account, spender string, coins int, tokenAddress string, minAmount string) (string, error)

保证用户发 erc20 的红包时,红包合约可以有权限操作用户的资产 @param account 要发红包的用户的账号,也许需要用到私钥来发起授权交易 @param chain evm 链 @param erc20Contract 要用作发红包的币种 @param coins 如果需要发起新授权,指定要授权的币个数 default 10^6 @param tokenAddress 代币地址 @param minAmount 最低应 approve 的数量,即合约需要的 approve 数量 @return 如果授权成功,不会返回错误,如果有新授权,会返回授权交易的 hash

func (*Chain) Erc20Token

func (c *Chain) Erc20Token(contractAddress string) TokenProtocol

func (*Chain) EstimateGasLimit

func (c *Chain) EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)

func (*Chain) EstimateTransactionFee

func (c *Chain) EstimateTransactionFee(transaction base.Transaction) (fee *base.OptionalString, err error)

func (*Chain) EstimateTransactionFeeUsePublicKey

func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction, pubkey string) (fee *base.OptionalString, err error)

func (*Chain) FetchRedPacketCreationDetail

func (c *Chain) FetchRedPacketCreationDetail(hash string) (*RedPacketDetail, error)

func (*Chain) FetchTransactionDetail

func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)

Fetch transaction details through transaction hash Support normal or erc20 transfer

func (*Chain) FetchTransactionStatus

func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus

Fetch transaction status through transaction hash

func (*Chain) GetEthChain

func (c *Chain) GetEthChain() (*EthChain, error)

func (*Chain) LatestBlockNumber

func (c *Chain) LatestBlockNumber() (s string, err error)

func (*Chain) LatestCallContract

func (c *Chain) LatestCallContract(msg *CallMsg) (string, error)

func (*Chain) MainEthToken

func (c *Chain) MainEthToken() TokenProtocol

func (*Chain) MainToken

func (c *Chain) MainToken() base.Token

func (*Chain) NonceOfAddress

func (c *Chain) NonceOfAddress(address string) (string, error)

获取交易的 nonce

func (*Chain) PendingCallContract

func (c *Chain) PendingCallContract(msg *CallMsg) (string, error)

func (*Chain) SendRawTransaction

func (c *Chain) SendRawTransaction(signedTx string) (string, error)

Send the raw transaction on-chain @return the hex hash string

func (*Chain) SendSignedTransaction

func (c *Chain) SendSignedTransaction(signedTxn base.SignedTransaction) (hash *base.OptionalString, err error)

func (*Chain) SignTransaction

func (c *Chain) SignTransaction(privateKey string, transaction *Transaction) (*base.OptionalString, error)

Sign a transaction @return signed tx hash

func (*Chain) SignTransactionWithAccount

func (c *Chain) SignTransactionWithAccount(account base.Account, transaction *Transaction) (*base.OptionalString, error)

func (*Chain) SignWithPrivateKeyData

func (c *Chain) SignWithPrivateKeyData(privateKeyData []byte, transaction *Transaction) (o *base.OptionalString, err error)

func (*Chain) SubmitTransactionData

func (c *Chain) SubmitTransactionData(account base.Account, to string, data []byte, value string) (string, error)

func (*Chain) SuggestGasPrice

func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)

func (*Chain) SuggestGasPriceEIP1559

func (c *Chain) SuggestGasPriceEIP1559() (*GasPrice, error)

The gas price use average grade default.

type ContractInfo

type ContractInfo struct {
	Abi     string
	Decimal string
}

func FindMainnetABI

func FindMainnetABI(contractCode string) (ContractInfo, bool)

FindMainnetABI 根据合约代号查找合约ABI的方法

type Contracts

type Contracts struct {
	USDT string
	USDC string
	UNI  string
	WETH string
	CAKE string
	DOGE string
	APE  string
}

func GetContractsByChainId

func GetContractsByChainId(chainId int64) []*Contracts

type Erc20Token

type Erc20Token struct {
	*Token

	ContractAddress string
}

func NewErc20Token

func NewErc20Token(chain *Chain, contractAddress string) *Erc20Token

func (*Erc20Token) Allowance

func (t *Erc20Token) Allowance(owner, spender string) (*big.Int, error)

func (*Erc20Token) Approve

func (t *Erc20Token) Approve(account *Account, spender string, amount *big.Int) (string, error)

func (*Erc20Token) BalanceOfAddress

func (t *Erc20Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Erc20Token) BuildTransfer

func (t *Erc20Token) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)

func (*Erc20Token) BuildTransferAll

func (t *Erc20Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error)

func (*Erc20Token) BuildTransferTx

func (t *Erc20Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Erc20Token) BuildTransferTxWithAccount

func (t *Erc20Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Erc20Token) CanTransferAll

func (t *Erc20Token) CanTransferAll() bool

func (*Erc20Token) Decimal

func (t *Erc20Token) Decimal() (int16, error)

func (*Erc20Token) Erc20TokenInfo

func (t *Erc20Token) Erc20TokenInfo() (*Erc20TokenInfo, error)

cannot get balance

func (*Erc20Token) EstimateGasFeeLayer2

func (t *Erc20Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)

func (*Erc20Token) EstimateGasLimit

func (t *Erc20Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)

func (*Erc20Token) TokenInfo

func (t *Erc20Token) TokenInfo() (*base.TokenInfo, error)

type Erc20TokenInfo

type Erc20TokenInfo struct {
	*base.TokenInfo

	ContractAddress string
	ChainId         string
	TokenIcon       string

	// Deprecated: Balance is not a token's info.
	Balance string
}

type Erc20TxParams

type Erc20TxParams struct {
	ToAddress string `json:"toAddress"`
	Amount    string `json:"amount"`
	Method    string `json:"method"`
}

type EthChain

type EthChain struct {
	RemoteRpcClient *ethclient.Client
	RpcClient       *rpc.Client
	// contains filtered or unexported fields
}

func GetConnection

func GetConnection(rpcUrl string) (*EthChain, error)

通过 rpcUrl, 获取 eth 的连接对象

func NewEthChain

func NewEthChain() *EthChain

func (*EthChain) Balance

func (e *EthChain) Balance(address string) (string, error)

Balance @title 主网代币余额查询 @description 返回主网代币余额,decimal为代币精度 @param (walletAddress) (string) 合约名称,钱包地址 @return (string,error) 代币余额,错误信息

func (*EthChain) BatchTransactionStatus

func (e *EthChain) BatchTransactionStatus(hashList []string) []string

批量获取交易的转账状态 @param hashList 要批量查询的交易的 hash 数组 @return 交易状态数组,它的顺序和 hashList 是保持一致的

func (*EthChain) BuildCallMethodTx

func (e *EthChain) BuildCallMethodTx(
	privateKey, contractAddress, abiStr, methodName string,
	opts *CallMethodOpts,
	erc20JsonParams string) (*BuildTxResult, error)

对合约进行调用

func (*EthChain) BuildCallMethodTxWithPayload

func (e *EthChain) BuildCallMethodTxWithPayload(
	privateKey, contractAddress, payload string, opts *CallMethodOpts) (*BuildTxResult, error)

func (*EthChain) BuildTransferTx

func (e *EthChain) BuildTransferTx(privateKey, toAddress string, opts *CallMethodOpts) (*BuildTxResult, error)

创建ETH转账交易

func (*EthChain) CallContractConstant

func (e *EthChain) CallContractConstant(out interface{}, contractAddress, abiStr, methodName string, opts *bind.CallOpts, params ...interface{}) (err error)

func (*EthChain) CallContractConstantWithPayload

func (e *EthChain) CallContractConstantWithPayload(out interface{}, contractAddress, payload string, outputTypes abi.Arguments, opts *bind.CallOpts) (err error)

func (*EthChain) Close

func (e *EthChain) Close()

func (*EthChain) ConnectRemote

func (e *EthChain) ConnectRemote(rpcUrl string) error

func (*EthChain) CreateRemote

func (e *EthChain) CreateRemote(rpcUrl string) (chain *EthChain, err error)

func (*EthChain) CreateRemoteWithTimeout

func (e *EthChain) CreateRemoteWithTimeout(rpcUrl string, timeout int64) (chain *EthChain, err error)

@param timeout time unit millsecond. 0 means use chain's default: 60000ms.

func (*EthChain) Erc20TokenInfo deprecated

func (e *EthChain) Erc20TokenInfo(contractAddress string, walletAddress string) (*Erc20TokenInfo, error)

Deprecated: Erc20TokenInfo is deprecated. Please Use Chain.Erc20Token().Erc20TokenInfo() @title Erc20代币基础信息 @description 返回代币基础信息 @param (contractAddress, walletAddress) (string,string) 合约名称,钱包地址 @return (*Erc20Token,error) Erc20Token,错误信息

func (*EthChain) EstimateContractGasLimit

func (e *EthChain) EstimateContractGasLimit(

	fromAddress,
	contractAddress,
	abiStr,
	methodName string,
	erc20JsonParams string) (gas string, err error)

erc20 代币 Transfer,Approve GasLimit 估计 var erc20TxParams Erc20TxParams

func (*EthChain) EstimateGasLimit

func (e *EthChain) EstimateGasLimit(fromAddress string, receiverAddress string, gasPrice string, amount string) (gas string, err error)

Estimated gasLimit @param fromAddress The address where the transfer originated @param receiverAddress The address where the transfer will received @param gasPrice Previously acquired or entered by the user @param amount The amount transferred @return Estimate gasLimit, is a `String` converted from `Uint64`

func (*EthChain) FetchTransactionDetail

func (e *EthChain) FetchTransactionDetail(hashString string) (detail *base.TransactionDetail, txn *types.Transaction, err error)

获取交易的详情 @param hashString 交易的 hash @return 交易详情 和 交易原文信息

func (*EthChain) FetchTransactionStatus

func (e *EthChain) FetchTransactionStatus(hashString string) base.TransactionStatus

获取交易的状态 @param hashString 交易的 hash

func (*EthChain) LatestBlockNumber

func (e *EthChain) LatestBlockNumber() (int64, error)

获取最新区块高度

func (*EthChain) MethodFromPayload

func (e *EthChain) MethodFromPayload(abiStr string, payloadStr string) (*abi.Method, error)

func (*EthChain) MethodIdFromMethodStr

func (e *EthChain) MethodIdFromMethodStr(methodStr string) string

func (*EthChain) Nonce

func (e *EthChain) Nonce(spenderAddressHex string) (string, error)

获取账户nonce

func (*EthChain) PackParams

func (e *EthChain) PackParams(inputs abi.Arguments, args ...interface{}) (string, error)

不带 0x 前缀

func (*EthChain) RecoverSignerAddress

func (e *EthChain) RecoverSignerAddress(msg, sig string) (*common.Address, error)

func (*EthChain) RecoverSignerAddressFromMsgHash

func (e *EthChain) RecoverSignerAddressFromMsgHash(msgHash, sig string) (*common.Address, error)

func (*EthChain) SdkBatchTokenBalance deprecated

func (e *EthChain) SdkBatchTokenBalance(contractListString, address string) (string, error)

Deprecated: SdkBatchTokenBalance is deprecated. Please Use Chain.BatchFetchErc20TokenBalance() instead.

func (*EthChain) SdkBatchTransactionStatus

func (e *EthChain) SdkBatchTransactionStatus(hashListString string) string

SDK 批量获取交易的转账状态,hash 列表和返回值,都只能用字符串,逗号隔开传递 @param hashListString 要批量查询的交易的 hash,用逗号拼接的字符串:"hash1,hash2,hash3" @return 批量的交易状态,它的顺序和 hashListString 是保持一致的: "status1,status2,status3"

func (*EthChain) SendRawTransaction

func (e *EthChain) SendRawTransaction(txHex string) (string, error)

对交易进行广播

func (*EthChain) SignHashForMsg

func (e *EthChain) SignHashForMsg(data string) (string, error)

以太坊的 hash 专门在数据前面加上了一段话

func (*EthChain) SignMsg

func (e *EthChain) SignMsg(privateKey string, data string) (string, error)

使用私钥对信息进行签名

func (*EthChain) SignTransaction

func (e *EthChain) SignTransaction(tx *types.Transaction, privateKey string) (*BuildTxResult, error)

SignTransaction @title SignTransaction @description 对交易进行签名 @param (tx, privateKey) (*types.Transaction,string) 合约名称,钱包地址 @return (*BuildTxResult,error) 签名结果,失败

func (*EthChain) SuggestGasPrice

func (e *EthChain) SuggestGasPrice() (string, error)

获取标准gas价格

func (*EthChain) TokenBalance

func (e *EthChain) TokenBalance(contractAddress, address string) (string, error)

TokenBalance @title Erc20代币余额 @description 返回erc20代币余额 @param (contractAddress,walletAddress) 合约地址,钱包地址 @return (string,error) 余额,错误信息

func (*EthChain) TokenDecimal

func (e *EthChain) TokenDecimal(contractAddress string) (int16, error)

TokenDecimal @title Erc20代币精度 @description 返回代币精度 @param (contractAddress) 合约地址 @return (string,error) 代币精度,错误信息

func (*EthChain) TokenName

func (e *EthChain) TokenName(contractAddress string) (string, error)

TokenName @title Erc20代币名称 @description 返回代币名称 @param (contractAddress) 合约地址 @return (string,error) 名称,错误信息

func (*EthChain) TokenSymbol

func (e *EthChain) TokenSymbol(contractAddress string) (string, error)

TokenSymbol @title Erc20代币符号 @description 返回代币符号 @param (contractAddress) 合约地址 @return (string,error) 符号,错误信息

func (*EthChain) TransactionByHash

func (e *EthChain) TransactionByHash(txHash string) (*TransactionByHashResult, error)

根据交易hash查询交易状态 TO-DO 返回更详细的信息,解析交易余额,交易动作

func (*EthChain) TransactionReceiptByHash

func (e *EthChain) TransactionReceiptByHash(txHash string) (*Receipt, error)

TransactionReceipt 是指交易的收据,每笔交易执行完 会产生一个收据,收据中包含交易的状态,交易的gas使用情况,交易执行是否成功的状态码等信息 交易收据属性列表: gasUsed: 交易执行时使用的gas数量 bloomFilter:交易信息日志检索 logInfoList: 交易日志集合 postTxState: 交易执行后的状态,1 表示成功,0表示失败

func (*EthChain) UnpackParams

func (e *EthChain) UnpackParams(out interface{}, inputs abi.Arguments, paramsStr string) error

func (*EthChain) WaitConfirm

func (e *EthChain) WaitConfirm(txHash string, interval time.Duration) *Receipt

type GasPrice

type GasPrice struct {
	// Pending block baseFee in wei.
	BaseFee            string
	SuggestPriorityFee string

	MaxPriorityFee string
	MaxFee         string
}

func (*GasPrice) UseAverage

func (g *GasPrice) UseAverage() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 1.5 MaxFee = (MaxPriorityFee + BaseFee) * 1.11

func (*GasPrice) UseHigh

func (g *GasPrice) UseHigh() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 2.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.5

func (*GasPrice) UseLow

func (g *GasPrice) UseLow() *GasPrice

MaxPriorityFee = SuggestPriorityFee * 1.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.0

func (*GasPrice) UseRate

func (g *GasPrice) UseRate(priorityRate, maxFeeRate float64) *GasPrice

MaxPriorityFee = SuggestPriorityFee * priorityRate MaxFee = (MaxPriorityFee + BaseFee) * maxFeeRate

type IChain

type IChain interface {
	base.Chain
	SubmitTransactionData(account base.Account, to string, data []byte, value string) (string, error)
	GetEthChain() (*EthChain, error)
	EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)
}

type Jsonable

type Jsonable interface {
	// 将对象转为 json 字符串
	JsonString() string
}

支持 对象 和 json 字符串 相互转换

type OptimismLayer2Gas

type OptimismLayer2Gas struct {
	L1GasLimit string
	L1GasPrice string
	L2GasLimit string
	L2GasPrice string
}

func (*OptimismLayer2Gas) GasFee

func (g *OptimismLayer2Gas) GasFee() string

l1GasLimit * l1GasPrice + l2Gaslimit * l2GasPrice

type RSS3Fetcher

type RSS3Fetcher struct {
	// Filter notes by networks.
	// Possible values: [ethereum, ethereum_classic, binance_smart_chain, polygon, zksync, xdai, arweave, arbitrum, optimism, fantom, avalanche, crossbell]
	Network string
	// Limit the page number of Notes returned by the server. max 500.
	Limit int
	// owner eth address
	Owner string

	NextCursor string
}

func NewRSS3FetcherWithNetwork

func NewRSS3FetcherWithNetwork(network string, owner string) *RSS3Fetcher

func (*RSS3Fetcher) FetchNFTs

func (f *RSS3Fetcher) FetchNFTs(owner string) (map[string][]*base.NFT, error)

func (*RSS3Fetcher) FetchNFTsJsonString

func (f *RSS3Fetcher) FetchNFTsJsonString(owner string) (*base.OptionalString, error)

@return json string that grouped by nft's collection

func (*RSS3Fetcher) FetchNotes

func (f *RSS3Fetcher) FetchNotes(cursor string) ([]RSS3Note, error)

func (*RSS3Fetcher) FetchNotesNext

func (f *RSS3Fetcher) FetchNotesNext() ([]RSS3Note, error)

type RSS3Metadata

type RSS3Metadata struct {
	Id              string `json:"id"`
	Name            string `json:"name"`
	Image           string `json:"image"`
	Standard        string `json:"standard"`
	Collection      string `json:"collection"`
	Descr           string `json:"description"`
	ContractAddress string `json:"contract_address"`
}

type RSS3Note

type RSS3Note struct {
	Timestamp  time.Time         `json:"timestamp"`
	HashString string            `json:"hash"`
	Success    bool              `json:"success"`
	Network    string            `json:"network"`
	Actions    []*RSS3NoteAction `json:"actions"`
}

type RSS3NoteAction

type RSS3NoteAction struct {
	From string `json:"address_from"`
	To   string `json:"address_to"`
	Tag  string `json:"tag"`
	Type string `json:"type"`

	Metadata    *RSS3Metadata `json:"metadata"`
	RelatedUrls []string      `json:"related_urls"`

	Timestamp  int64
	HashString string
}

func (*RSS3NoteAction) IsNftAction

func (a *RSS3NoteAction) IsNftAction() bool

func (*RSS3NoteAction) Nft

func (a *RSS3NoteAction) Nft() *base.NFT

func (*RSS3NoteAction) NftIdentifierKey

func (a *RSS3NoteAction) NftIdentifierKey() string

@return nft identifierKey if the action is a nft action, else return empty

func (*RSS3NoteAction) RelatedScanUrl

func (a *RSS3NoteAction) RelatedScanUrl() string

type Receipt

type Receipt struct {
	types.Receipt

	// Optimism Layer2 gas info
	L1Fee *big.Int `json:"l1Fee"`

	// Arbitrum Layer2 gas info
	EffectiveGasPrice *big.Int `json:"effectiveGasPrice"`
}

customReceipt is inherit from eth/core types.Receipt, and added some necessary properties

func (*Receipt) UnmarshalJSON

func (r *Receipt) UnmarshalJSON(data []byte) error

type RedPacketAction

type RedPacketAction struct {
	Method string
	Params []interface{}
}

func NewRedPacketActionClose deprecated

func NewRedPacketActionClose(packetId int64, creator string) (*RedPacketAction, error)

结束红包领取 的操作

Deprecated: use base.NewRedPacketActionClose

func NewRedPacketActionCreate deprecated

func NewRedPacketActionCreate(erc20TokenAddress string, count int, amount string) (*RedPacketAction, error)

用户发红包 的操作

Deprecated: use base.NewRedPacketActionCreate

func NewRedPacketActionOpen deprecated

func NewRedPacketActionOpen(packetId int64, addresses []string, amounts []string) (*RedPacketAction, error)

批量打开红包 的操作

Deprecated: use base.NewRedPacketActionOpen

func (*RedPacketAction) EnsureApprovedTokens deprecated

func (rpa *RedPacketAction) EnsureApprovedTokens(account *Account, chain *Chain, spender string, coins int) (string, error)

保证用户发 erc20 的红包时,红包合约可以有权限操作用户的资产 @param account 要发红包的用户的账号,也许需要用到私钥来发起授权交易 @param chain evm 链 @param erc20Contract 要用作发红包的币种 @param coins 如果需要发起新授权,指定要授权的币个数 default 10^6 @return 如果授权成功,不会返回错误,如果有新授权,会返回授权交易的 hash

Deprecated: use chain.EnsureApprovedTokens

func (*RedPacketAction) EstimateAmount

func (rpa *RedPacketAction) EstimateAmount() string

func (*RedPacketAction) TransactionFrom deprecated

func (rpa *RedPacketAction) TransactionFrom(fromAddress, contractAddress string, chain *Chain) (*Transaction, error)

@param fromAddress 要调用红包业务的操作者 @param contractAddress 红包合约地址 @param chain 要发红包的链

Deprecated: use NewRedPacketContract() get base.RedPacketContract, and SendTransaction(base.Account, *base.RedPacketAction)

type RedPacketDetail deprecated

type RedPacketDetail struct {
	*base.TransactionDetail

	AmountName    string
	AmountDecimal int16
}

Deprecated: use base.RedPacketDetail

func NewRedPacketDetail deprecated

func NewRedPacketDetail() *RedPacketDetail

Deprecated: use base.NewRedPacketDetail

func NewRedPacketDetailWithJsonString deprecated

func NewRedPacketDetailWithJsonString(s string) (*RedPacketDetail, error)

Deprecated: use base.NewRedPacketDetailWithJsonString

func (*RedPacketDetail) JsonString

func (d *RedPacketDetail) JsonString() string

type RpcConfig

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

type RpcInfo

type RpcInfo struct {
	ChainId string
	Url     string

	Contracts *Contracts
	// contains filtered or unexported fields
}

func GetRpcInfoByChainId

func GetRpcInfoByChainId(chainId int64) *RpcInfo

GetRpcInfoByChainId 根据chainId返回对应的RpcInfo

func (*RpcInfo) Chain

func (n *RpcInfo) Chain() *Chain

type RpcReachability

type RpcReachability struct {
}

func NewRpcReachability

func NewRpcReachability() *RpcReachability

func (*RpcReachability) LatencyOf

func (r *RpcReachability) LatencyOf(rpc string, timeout int64) (l *base.RpcLatency, err error)

@return latency (ms) of rpc query blockNumber. -1 means the connection failed.

type Token

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

func NewToken

func NewToken(chain *Chain) *Token

func (*Token) BalanceOfAccount

func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Token) BalanceOfAddress

func (t *Token) BalanceOfAddress(address string) (*base.Balance, error)

func (*Token) BalanceOfPublicKey

func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Token) BuildTransfer

func (t *Token) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)

func (*Token) BuildTransferAll

func (t *Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error)

func (*Token) BuildTransferTx

func (t *Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)

func (*Token) BuildTransferTxWithAccount

func (t *Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)

func (*Token) CanTransferAll

func (t *Token) CanTransferAll() bool

func (*Token) Chain

func (t *Token) Chain() base.Chain

func (*Token) EstimateGasFeeLayer2

func (t *Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)

func (*Token) EstimateGasLimit

func (t *Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)

func (*Token) TokenInfo

func (t *Token) TokenInfo() (*base.TokenInfo, error)

Warning: Main token does not support

type TokenProtocol

type TokenProtocol interface {
	base.Token

	// need `fromAddress`, `receiverAddress`, `gasPrice`, `gasLimit`, `amount`
	EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
	EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)
	BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
	BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
}

type Transaction

type Transaction struct {
	Nonce    string // nonce of sender account
	GasPrice string // wei per gas
	GasLimit string // gas limit
	To       string // receiver
	Value    string // wei amount
	Data     string // contract invocation input data

	// EIP1559, Default is ""
	MaxPriorityFeePerGas string
}

func NewTransaction

func NewTransaction(nonce, gasPrice, gasLimit, to, value, data string) *Transaction

func NewTransactionFromHex

func NewTransactionFromHex(hexData string) (*Transaction, error)

func (*Transaction) GetRawTx

func (tx *Transaction) GetRawTx() (*types.Transaction, error)

func (*Transaction) MaxFee

func (tx *Transaction) MaxFee() string

This is an alias property for GasPrice in order to support EIP1559

func (*Transaction) SetMaxFee

func (tx *Transaction) SetMaxFee(maxFee string)

This is an alias property for GasPrice in order to support EIP1559

func (*Transaction) SignWithAccount

func (t *Transaction) SignWithAccount(account base.Account) (signedTx *base.OptionalString, err error)

func (*Transaction) SignedTransactionWithAccount

func (t *Transaction) SignedTransactionWithAccount(account base.Account) (signedTx base.SignedTransaction, err error)

func (*Transaction) TotalAmount

func (tx *Transaction) TotalAmount() string

@return gasPrice * gasLimit + value

func (*Transaction) TransformToErc20Transaction

func (tx *Transaction) TransformToErc20Transaction(contractAddress string) error

type TransactionByHashResult

type TransactionByHashResult struct {
	SignedTx    *types.Transaction
	From        common.Address
	IsPending   bool   // 交易是否处于Pending状态
	Status      string // 0: 交易失败, 1: 交易成功
	GasUsed     string // 实际花费gas
	BlockNumber string // 区块高度
}

type UrlParam

type UrlParam struct {
	RpcUrl string
	WsUrl  string
}

type Util

type Util struct {
}

func NewUtil

func NewUtil() *Util

func (*Util) DecodeAddressToPublicKey

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

Warning: eth cannot support decode address to public key

func (*Util) EncodePublicKeyToAddress

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

func (*Util) IsValidAddress

func (u *Util) IsValidAddress(address string) bool

Check if address is 40 hexadecimal characters

Jump to

Keyboard shortcuts

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