Documentation ¶
Index ¶
- Constants
- func DecodeAddressToPublicKey(address string) (string, error)
- func EncodeAbiData(abiString, method string, params ...interface{}) ([]byte, error)
- func EncodeErc20Approve(spender string, amount *big.Int) ([]byte, error)
- func EncodeErc20Transfer(toAddress, amount string) ([]byte, error)
- func EncodePublicKeyToAddress(publicKey string) (string, error)
- func GetChainId(e *EthChain) (string, error)
- func IsValidAddress(address string) bool
- func IsValidEIP55Address(address string) bool
- func PrivateKeyToAddress(privateKey string) (string, error)
- func SignHashForMsg(data string) []byte
- func TransformEIP55Address(address string) (string, error)
- func VerifySignature(pubkey, message, signedMsg string) bool
- type Account
- func (a *Account) Address() string
- func (a *Account) PrivateKey() ([]byte, error)
- func (a *Account) PrivateKeyHex() (string, error)
- func (a *Account) PublicKey() []byte
- func (a *Account) PublicKeyHex() string
- func (a *Account) Sign(message []byte, password string) ([]byte, error)
- func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)
- type BuildTxResult
- type CallMethodOpts
- type CallMethodOptsBigInt
- type CallMsg
- func (msg *CallMsg) GetData() []byte
- func (msg *CallMsg) GetDataHex() string
- func (msg *CallMsg) GetFrom() string
- func (msg *CallMsg) GetGasLimit() string
- func (msg *CallMsg) GetGasPrice() string
- func (msg *CallMsg) GetTo() string
- func (msg *CallMsg) GetValue() string
- func (msg *CallMsg) SetData(data []byte)
- func (msg *CallMsg) SetDataHex(hex string)
- func (msg *CallMsg) SetFrom(address string)
- func (msg *CallMsg) SetGasLimit(gas string)
- func (msg *CallMsg) SetGasPrice(price string)
- func (msg *CallMsg) SetTo(address string)
- func (msg *CallMsg) SetValue(value string)
- func (msg *CallMsg) SetValueHex(hex string)
- func (msg *CallMsg) TransferToTransaction() *Transaction
- type Chain
- func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)
- func (c *Chain) BalanceOfAddress(address string) (*base.Balance, error)
- func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)
- func (c *Chain) BatchErc20TokenBalance(contractList []string, address string) ([]string, error)
- func (c *Chain) BatchFetchErc20TokenBalance(contractListString, address string) (string, error)
- func (c *Chain) BatchFetchTransactionStatus(hashListString string) string
- func (c *Chain) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
- func (c *Chain) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
- func (c *Chain) CallContract(msg *CallMsg, blockNumber int64) (string, error)
- func (c *Chain) ChainId() (string, error)
- func (c *Chain) Erc20Token(contractAddress string) TokenProtocol
- func (c *Chain) EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)
- func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)
- func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus
- func (c *Chain) LatestBlockNumber() (s string, err error)
- func (c *Chain) LatestCallContract(msg *CallMsg) (string, error)
- func (c *Chain) MainEthToken() TokenProtocol
- func (c *Chain) MainToken() base.Token
- func (c *Chain) NonceOfAddress(address string) (string, error)
- func (c *Chain) PendingCallContract(msg *CallMsg) (string, error)
- func (c *Chain) SendRawTransaction(signedTx string) (string, error)
- func (c *Chain) SignTransaction(privateKey string, transaction *Transaction) (*base.OptionalString, error)
- func (c *Chain) SignTransactionWithAccount(account base.Account, transaction *Transaction) (*base.OptionalString, error)
- func (c *Chain) SignWithPrivateKeyData(privateKeyData []byte, transaction *Transaction) (o *base.OptionalString, err error)
- func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)
- func (c *Chain) SuggestGasPriceEIP1559() (*GasPrice, error)
- type CoinUtildeprecated
- func (u *CoinUtil) BuildTransferTx(privateKey, receiverAddress, nonce, gasPrice, gasLimit, amount string) (*base.OptionalString, error)deprecated
- func (u *CoinUtil) CoinInfo() (*Erc20TokenInfo, error)deprecated
- func (u *CoinUtil) EstimateGasLimit(receiverAddress, gasPrice, amount string) (string, error)deprecated
- func (u *CoinUtil) FetchTransactionDetail(hashString string) (*base.TransactionDetail, error)deprecated
- func (u *CoinUtil) FetchTransactionStatus(hashString string) base.TransactionStatusdeprecated
- func (u *CoinUtil) IsMainCoin() bool
- func (u *CoinUtil) Nonce() (string, error)deprecated
- func (u *CoinUtil) QueryBalance() (string, error)deprecated
- func (u *CoinUtil) SdkBatchTransactionStatus(hashListString string) (string, error)deprecated
- func (u *CoinUtil) SendRawTransaction(txHex string) (string, error)deprecated
- type Erc20Token
- func (t *Erc20Token) Allowance(owner, spender string) (*big.Int, error)
- func (t *Erc20Token) Approve(account *Account, spender string, amount *big.Int) (string, error)
- func (t *Erc20Token) BalanceOfAddress(address string) (*base.Balance, error)
- func (t *Erc20Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
- func (t *Erc20Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
- func (t *Erc20Token) Decimal() (int16, error)
- func (t *Erc20Token) Erc20TokenInfo() (*Erc20TokenInfo, error)
- func (t *Erc20Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
- func (t *Erc20Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)
- func (t *Erc20Token) TokenInfo() (*base.TokenInfo, error)
- type Erc20TokenInfo
- type Erc20TxParams
- type EthChain
- func (e *EthChain) Balance(address string) (string, error)
- func (e *EthChain) BatchTransactionStatus(hashList []string) []string
- func (e *EthChain) BuildCallMethodTx(privateKey, contractAddress, abiStr, methodName string, opts *CallMethodOpts, ...) (*BuildTxResult, error)
- func (e *EthChain) BuildCallMethodTxWithPayload(privateKey, contractAddress, payload string, opts *CallMethodOpts) (*BuildTxResult, error)
- func (e *EthChain) BuildTransferTx(privateKey, toAddress string, opts *CallMethodOpts) (*BuildTxResult, error)
- func (e *EthChain) CallContractConstant(out interface{}, contractAddress, abiStr, methodName string, ...) (err error)
- func (e *EthChain) CallContractConstantWithPayload(out interface{}, contractAddress, payload string, outputTypes abi.Arguments, ...) (err error)
- func (e *EthChain) Close()
- func (e *EthChain) ConnectRemote(rpcUrl string) error
- func (e *EthChain) CreateRemote(rpcUrl string) (chain *EthChain, err error)
- func (e *EthChain) CreateRemoteWithTimeout(rpcUrl string, timeout int64) (chain *EthChain, err error)
- func (e *EthChain) Erc20TokenInfo(contractAddress string, walletAddress string) (*Erc20TokenInfo, error)deprecated
- func (e *EthChain) EstimateContractGasLimit(fromAddress, contractAddress, abiStr, methodName string, ...) (gas string, err error)
- func (e *EthChain) EstimateGasLimit(fromAddress string, receiverAddress string, gasPrice string, amount string) (gas string, err error)
- func (e *EthChain) FetchTransactionDetail(hashString string) (detail *base.TransactionDetail, err error)
- func (e *EthChain) FetchTransactionStatus(hashString string) base.TransactionStatus
- func (e *EthChain) LatestBlockNumber() (int64, error)
- func (e *EthChain) MethodFromPayload(abiStr string, payloadStr string) (*abi.Method, error)
- func (e *EthChain) MethodIdFromMethodStr(methodStr string) string
- func (e *EthChain) Nonce(spenderAddressHex string) (string, error)
- func (e *EthChain) PackParams(inputs abi.Arguments, args ...interface{}) (string, error)
- func (e *EthChain) RecoverSignerAddress(msg, sig string) (*common.Address, error)
- func (e *EthChain) RecoverSignerAddressFromMsgHash(msgHash, sig string) (*common.Address, error)
- func (e *EthChain) SdkBatchTokenBalance(contractListString, address string) (string, error)deprecated
- func (e *EthChain) SdkBatchTransactionStatus(hashListString string) string
- func (e *EthChain) SendRawTransaction(txHex string) (string, error)
- func (e *EthChain) SignHashForMsg(data string) (string, error)
- func (e *EthChain) SignMsg(privateKey string, data string) (string, error)
- func (e *EthChain) SignTransaction(tx *types.Transaction, privateKey string) (*BuildTxResult, error)
- func (e *EthChain) SuggestGasPrice() (string, error)
- func (e *EthChain) TokenBalance(contractAddress, address string) (string, error)
- func (e *EthChain) TokenDecimal(contractAddress string) (int16, error)
- func (e *EthChain) TokenName(contractAddress string) (string, error)
- func (e *EthChain) TokenSymbol(contractAddress string) (string, error)
- func (e *EthChain) TransactionByHash(txHash string) (*TransactionByHashResult, error)
- func (e *EthChain) TransactionReceiptByHash(txHash string) (*Receipt, error)
- func (e *EthChain) UnpackParams(out interface{}, inputs abi.Arguments, paramsStr string) error
- func (e *EthChain) WaitConfirm(txHash string, interval time.Duration) *Receipt
- type GasPrice
- type Jsonable
- type OptimismLayer2Gas
- type Receipt
- type RedPacketAction
- func NewRedPacketActionClose(packetId int64, creator string) (*RedPacketAction, error)
- func NewRedPacketActionCreate(erc20TokenAddress string, count int, amount string) (*RedPacketAction, error)
- func NewRedPacketActionOpen(packetId int64, addresses []string, amounts []string) (*RedPacketAction, error)
- type RpcLatency
- type RpcReachability
- type RpcReachabilityDelegate
- type Token
- func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)
- func (t *Token) BalanceOfAddress(address string) (*base.Balance, error)
- func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)
- func (t *Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
- func (t *Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
- func (t *Token) Chain() base.Chain
- func (t *Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
- func (t *Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)
- func (t *Token) TokenInfo() (*base.TokenInfo, error)
- type TokenProtocol
- type Transaction
- type TransactionByHashResult
- type UrlParam
- type Util
Constants ¶
const ( // ERC20 交易method ERC20_METHOD_TRANSFER = "transfer" ERC20_METHOD_APPROVE = "approve" )
const ( DEFAULT_CONTRACT_GAS_LIMIT = "63000" DEFAULT_ETH_GAS_LIMIT = "21000" // 当前网络 standard gas price DEFAULT_ETH_GAS_PRICE = "20000000000" )
默认gas limit估算失败后,21000 * 3 = 63000
const ( RPAMethodCreate = "create" RPAMethodOpen = "open" RPAMethodClose = "close" )
const ( // 合约 ABI json文件,查询ERC20 相关代币信息需要使用 ABI 文件 Erc20AbiStr = `` /* 4592-byte string literal not displayed */ )
const RedPacketABI = `` /* 4896-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func DecodeAddressToPublicKey ¶ added in v0.2.0
Warning: eth cannot support decode address to public key
func EncodeAbiData ¶ added in v0.2.6
func EncodeErc20Approve ¶ added in v0.2.6
func EncodeErc20Transfer ¶ added in v0.2.4
Encode erc20 transfer data
func EncodePublicKeyToAddress ¶ added in v0.2.0
func IsValidAddress ¶ added in v0.1.2
Check if address is 40 hexadecimal characters
func IsValidEIP55Address ¶ added in v0.2.5
It will check based on eip55 rules
func SignHashForMsg ¶ added in v0.2.3
以太坊的 hash 专门在数据前面加上了一段话
func TransformEIP55Address ¶ added in v0.2.0
func VerifySignature ¶ added in v0.2.4
Types ¶
type Account ¶ added in v0.2.0
type Account struct { *Util // contains filtered or unexported fields }
func EthAccountWithPrivateKey ¶ added in v0.2.6
We cannot use name `NewAccountWithPrivateKey`, because android not support.
func NewAccountWithMnemonic ¶ added in v0.2.0
func (*Account) PrivateKey ¶ added in v0.2.0
@return privateKey data
func (*Account) PrivateKeyHex ¶ added in v0.2.0
@return privateKey string that will start with 0x.
func (*Account) PublicKeyHex ¶ added in v0.2.0
The ethereum public key is same as address in coming @return publicKey string that will start with 0x.
type BuildTxResult ¶
type BuildTxResult struct { SignedTx *types.Transaction TxHex string }
type CallMethodOpts ¶
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 ¶ added in v0.2.0
type CallMsg struct {
// contains filtered or unexported fields
}
CallMsg contains parameters for contract calls.
func NewCallMsg ¶ added in v0.2.0
func NewCallMsg() *CallMsg
NewCallMsg creates an empty contract call parameter list.
func (*CallMsg) GetDataHex ¶ added in v0.2.1
func (*CallMsg) GetGasLimit ¶ added in v0.2.5
func (*CallMsg) GetGasPrice ¶ added in v0.2.0
func (*CallMsg) SetDataHex ¶ added in v0.2.1
func (*CallMsg) SetGasLimit ¶ added in v0.2.5
func (*CallMsg) SetGasPrice ¶ added in v0.2.0
func (*CallMsg) SetValueHex ¶ added in v0.2.3
Set amount with hexadecimal number
func (*CallMsg) TransferToTransaction ¶ added in v0.2.6
func (msg *CallMsg) TransferToTransaction() *Transaction
type Chain ¶ added in v0.2.0
type Chain struct {
RpcUrl string
}
func NewChainWithRpc ¶ added in v0.2.0
func (*Chain) BalanceOfAccount ¶ added in v0.2.0
func (*Chain) BalanceOfAddress ¶ added in v0.2.0
func (*Chain) BalanceOfPublicKey ¶ added in v0.2.0
func (*Chain) BatchErc20TokenBalance ¶ added in v0.2.0
批量请求代币余额 @param contractList 批量查询的代币的合约地址数组 @param address 用户的钱包地址 @return 余额数组,顺序与传入的 contractList 是保持一致的 @throw 如果任意一个代币请求余额出错时,会抛出错误
func (*Chain) BatchFetchErc20TokenBalance ¶ added in v0.2.0
SDK 批量请求代币余额,因为 golang 导出的方法不支持数组,因此传参和返回都只能用字符串 @param contractListString 批量查询的代币的合约地址字符串,用逗号隔开,例如: "add1,add2,add3" @param address 用户的钱包地址 @return 余额列表,顺序与传入合约顺序是保持一致的,例如: "b1,b2,b3" @throw 如果任意一个代币请求余额出错时,会抛出错误
func (*Chain) BatchFetchTransactionStatus ¶ added in v0.2.0
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 ¶ added in v0.2.6
func (c *Chain) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
func (*Chain) BuildTransferTxWithAccount ¶ added in v0.2.6
func (c *Chain) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
func (*Chain) CallContract ¶ added in v0.2.0
call eth_call method @param blockNumber Especially -2 is the latest block, -1 is pending block.
func (*Chain) Erc20Token ¶ added in v0.2.0
func (c *Chain) Erc20Token(contractAddress string) TokenProtocol
func (*Chain) EstimateGasLimit ¶ added in v0.2.4
func (c *Chain) EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)
func (*Chain) FetchTransactionDetail ¶ added in v0.2.0
func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)
Fetch transaction details through transaction hash
func (*Chain) FetchTransactionStatus ¶ added in v0.2.0
func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus
Fetch transaction status through transaction hash
func (*Chain) LatestBlockNumber ¶ added in v0.2.1
func (*Chain) LatestCallContract ¶ added in v0.2.1
func (*Chain) MainEthToken ¶ added in v0.2.0
func (c *Chain) MainEthToken() TokenProtocol
func (*Chain) NonceOfAddress ¶ added in v0.2.0
获取交易的 nonce
func (*Chain) PendingCallContract ¶ added in v0.2.0
func (*Chain) SendRawTransaction ¶ added in v0.2.0
Send the raw transaction on-chain @return the hex hash string
func (*Chain) SignTransaction ¶ added in v0.2.3
func (c *Chain) SignTransaction(privateKey string, transaction *Transaction) (*base.OptionalString, error)
Sign a transaction @return signed tx hash
func (*Chain) SignTransactionWithAccount ¶ added in v0.2.3
func (c *Chain) SignTransactionWithAccount(account base.Account, transaction *Transaction) (*base.OptionalString, error)
func (*Chain) SignWithPrivateKeyData ¶ added in v0.2.3
func (c *Chain) SignWithPrivateKeyData(privateKeyData []byte, transaction *Transaction) (o *base.OptionalString, err error)
func (*Chain) SuggestGasPrice ¶ added in v0.2.0
func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)
func (*Chain) SuggestGasPriceEIP1559 ¶ added in v0.2.3
The gas price use average grade default.
type CoinUtil
deprecated
added in
v0.1.2
type CoinUtil struct { // 链的 RPC 地址 RpcUrl string // 币种的合约地址,如果为 nil,表示是主网的币 ContractAddress string // 用户的钱包地址 WalletAddress string }
Deprecated: CoinUtil is deprecated. Please Use EthChain instead.
func NewCoinUtilWithRpc
deprecated
added in
v0.1.2
func (*CoinUtil) BuildTransferTx
deprecated
added in
v0.1.2
func (u *CoinUtil) BuildTransferTx(privateKey, receiverAddress, nonce, gasPrice, gasLimit, amount string) (*base.OptionalString, error)
Deprecated: BuildTransferTx is deprecated. Please Use Chain.Token().BuildTransferTx() instead.
func (*CoinUtil) CoinInfo
deprecated
added in
v0.1.2
func (u *CoinUtil) CoinInfo() (*Erc20TokenInfo, error)
Deprecated: CoinInfo is deprecated.
func (*CoinUtil) EstimateGasLimit
deprecated
added in
v0.1.2
func (*CoinUtil) FetchTransactionDetail
deprecated
added in
v0.1.2
func (u *CoinUtil) FetchTransactionDetail(hashString string) (*base.TransactionDetail, error)
Deprecated: FetchTransactionDetail is deprecated. Please Use Chain.FetchTransactionDetail() instead.
func (*CoinUtil) FetchTransactionStatus
deprecated
added in
v0.1.2
func (u *CoinUtil) FetchTransactionStatus(hashString string) base.TransactionStatus
Deprecated: FetchTransactionStatus is deprecated. Please Use Chain.FetchTransactionStatus() instead.
func (*CoinUtil) QueryBalance
deprecated
added in
v0.1.2
func (*CoinUtil) SdkBatchTransactionStatus
deprecated
added in
v0.1.5
func (*CoinUtil) SendRawTransaction
deprecated
added in
v0.1.2
type Erc20Token ¶
func NewErc20Token ¶ added in v0.2.0
func NewErc20Token(chain *Chain, contractAddress string) *Erc20Token
func (*Erc20Token) Allowance ¶ added in v0.2.6
func (t *Erc20Token) Allowance(owner, spender string) (*big.Int, error)
func (*Erc20Token) BalanceOfAddress ¶ added in v0.2.0
func (t *Erc20Token) BalanceOfAddress(address string) (*base.Balance, error)
func (*Erc20Token) BuildTransferTx ¶ added in v0.2.0
func (t *Erc20Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
func (*Erc20Token) BuildTransferTxWithAccount ¶ added in v0.2.3
func (t *Erc20Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
func (*Erc20Token) Decimal ¶
func (t *Erc20Token) Decimal() (int16, error)
func (*Erc20Token) Erc20TokenInfo ¶ added in v0.2.0
func (t *Erc20Token) Erc20TokenInfo() (*Erc20TokenInfo, error)
cannot get balance
func (*Erc20Token) EstimateGasFeeLayer2 ¶ added in v0.2.5
func (t *Erc20Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
func (*Erc20Token) EstimateGasLimit ¶ added in v0.2.0
func (t *Erc20Token) EstimateGasLimit(fromAddress, receiverAddress, gasPrice, amount string) (string, error)
type Erc20TokenInfo ¶ added in v0.2.0
type Erc20TxParams ¶
type EthChain ¶
type EthChain struct { RemoteRpcClient *ethclient.Client RpcClient *rpc.Client // contains filtered or unexported fields }
func GetConnection ¶ added in v0.1.2
通过 rpcUrl, 获取 eth 的连接对象
func NewEthChain ¶
func NewEthChain() *EthChain
func (*EthChain) Balance ¶
@title 主网代币余额查询 @description 返回主网代币余额,decimal为代币精度 @auth 清欢 @param (walletAddress) (string) 合约名称,钱包地址 @return (string,error) 代币余额,错误信息
func (*EthChain) BatchTransactionStatus ¶ added in v0.1.2
批量获取交易的转账状态 @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 (*EthChain) CallContractConstantWithPayload ¶
func (*EthChain) ConnectRemote ¶ added in v0.1.2
func (*EthChain) CreateRemote ¶
func (*EthChain) CreateRemoteWithTimeout ¶ added in v0.2.5
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 返回代币基础信息 @auth 清欢 @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 ¶ added in v0.1.2
func (e *EthChain) FetchTransactionDetail(hashString string) (detail *base.TransactionDetail, err error)
获取交易的详情 @param hashString 交易的 hash @return 详情对象,该对象无法提供 CID 信息
func (*EthChain) FetchTransactionStatus ¶ added in v0.1.2
func (e *EthChain) FetchTransactionStatus(hashString string) base.TransactionStatus
获取交易的状态 @param hashString 交易的 hash
func (*EthChain) MethodFromPayload ¶
func (*EthChain) MethodIdFromMethodStr ¶
func (*EthChain) PackParams ¶
不带 0x 前缀
func (*EthChain) RecoverSignerAddress ¶
func (*EthChain) RecoverSignerAddressFromMsgHash ¶
func (*EthChain) SdkBatchTokenBalance
deprecated
added in
v0.1.2
func (*EthChain) SdkBatchTransactionStatus ¶ added in v0.1.2
SDK 批量获取交易的转账状态,hash 列表和返回值,都只能用字符串,逗号隔开传递 @param hashListString 要批量查询的交易的 hash,用逗号拼接的字符串:"hash1,hash2,hash3" @return 批量的交易状态,它的顺序和 hashListString 是保持一致的: "status1,status2,status3"
func (*EthChain) SendRawTransaction ¶
对交易进行广播
func (*EthChain) SignHashForMsg ¶
以太坊的 hash 专门在数据前面加上了一段话
func (*EthChain) SignTransaction ¶
func (e *EthChain) SignTransaction(tx *types.Transaction, privateKey string) (*BuildTxResult, error)
@title SignTransaction @description 对交易进行签名 @auth 清欢 @param (tx, privateKey) (*types.Transaction,string) 合约名称,钱包地址 @return (*BuildTxResult,error) 签名结果,失败
func (*EthChain) TokenBalance ¶
@title Erc20代币余额 @description 返回erc20代币余额 @auth 清欢 @param (contractAddress,walletAddress) 合约地址,钱包地址 @return (string,error) 余额,错误信息
func (*EthChain) TokenDecimal ¶
@title Erc20代币精度 @description 返回代币精度 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 代币精度,错误信息
func (*EthChain) TokenName ¶
@title Erc20代币名称 @description 返回代币名称 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 名称,错误信息
func (*EthChain) TokenSymbol ¶
@title Erc20代币符号 @description 返回代币符号 @auth 清欢 @param (contractAddress) 合约地址 @return (string,error) 符号,错误信息
func (*EthChain) TransactionByHash ¶
func (e *EthChain) TransactionByHash(txHash string) (*TransactionByHashResult, error)
根据交易hash查询交易状态 TO-DO 返回更详细的信息,解析交易余额,交易动作
func (*EthChain) TransactionReceiptByHash ¶
TransactionReceipt 是指交易的收据,每笔交易执行完 会产生一个收据,收据中包含交易的状态,交易的gas使用情况,交易执行是否成功的状态码等信息 交易收据属性列表: gasUsed: 交易执行时使用的gas数量 bloomFilter:交易信息日志检索 logInfoList: 交易日志集合 postTxState: 交易执行后的状态,1 表示成功,0表示失败
func (*EthChain) UnpackParams ¶
type GasPrice ¶ added in v0.2.3
type GasPrice struct { // Pending block baseFee in wei. BaseFee string SuggestPriorityFee string MaxPriorityFee string MaxFee string }
func (*GasPrice) UseAverage ¶ added in v0.2.3
MaxPriorityFee = SuggestPriorityFee * 1.5 MaxFee = (MaxPriorityFee + BaseFee) * 1.11
func (*GasPrice) UseHigh ¶ added in v0.2.3
MaxPriorityFee = SuggestPriorityFee * 2.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.5
type Jsonable ¶
type Jsonable interface { // 将对象转为 json 字符串 JsonString() string }
支持 对象 和 json 字符串 相互转换
type OptimismLayer2Gas ¶ added in v0.2.5
type OptimismLayer2Gas struct { L1GasLimit string L1GasPrice string L2GasLimit string L2GasPrice string }
func (*OptimismLayer2Gas) GasFee ¶ added in v0.2.5
func (g *OptimismLayer2Gas) GasFee() string
l1GasLimit * l1GasPrice + l2Gaslimit * l2GasPrice
type Receipt ¶ added in v0.2.5
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 ¶ added in v0.2.5
type RedPacketAction ¶ added in v0.2.6
type RedPacketAction struct { Method string Params []interface{} }
func NewRedPacketActionClose ¶ added in v0.2.6
func NewRedPacketActionClose(packetId int64, creator string) (*RedPacketAction, error)
结束红包领取 的操作
func NewRedPacketActionCreate ¶ added in v0.2.6
func NewRedPacketActionCreate(erc20TokenAddress string, count int, amount string) (*RedPacketAction, error)
用户发红包 的操作
func NewRedPacketActionOpen ¶ added in v0.2.6
func NewRedPacketActionOpen(packetId int64, addresses []string, amounts []string) (*RedPacketAction, error)
批量打开红包 的操作
func (*RedPacketAction) EnsureApprovedTokens ¶ added in v0.2.6
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
func (*RedPacketAction) EstimateAmount ¶ added in v0.2.6
func (rpa *RedPacketAction) EstimateAmount() string
func (*RedPacketAction) TransactionFrom ¶ added in v0.2.6
func (rpa *RedPacketAction) TransactionFrom(fromAddress, contractAddress string, chain *Chain) (*Transaction, error)
@param fromAddress 要调用红包业务的操作者 @param contractAddress 红包合约地址 @param chain 要发红包的链
type RpcLatency ¶ added in v0.2.5
type RpcReachability ¶ added in v0.2.5
type RpcReachability struct { // The number of network connectivity tests to be performed per rpc. 0 means infinite, default is 1 ReachCount int // Timeout for each connectivity test (ms). default 20000ms Timeout int64 // Time interval between two network connectivity tests (ms). default 1500ms Delay int64 // contains filtered or unexported fields }
func NewRpcReachability ¶ added in v0.2.5
func NewRpcReachability() *RpcReachability
func (*RpcReachability) StartConnectivityDelegate ¶ added in v0.2.5
func (r *RpcReachability) StartConnectivityDelegate(rpcList string, delegate RpcReachabilityDelegate)
@param rpcList string of rpcs like "rpc1,rpc2,rpc3,..."
func (*RpcReachability) StartConnectivitySync ¶ added in v0.2.5
func (r *RpcReachability) StartConnectivitySync(rpcList string) string
@param rpcList string of rpcs like "rpc1,rpc2,rpc3,..." @return jsonString sorted array base of tatency like "[{rpcUrl:rpc1,latency:100}, {rpcUrl:rpc2, latency:111}, ...]" latency unit is ms. -1 means the connection failed
func (*RpcReachability) StopConnectivity ¶ added in v0.2.5
func (r *RpcReachability) StopConnectivity()
type RpcReachabilityDelegate ¶ added in v0.2.5
type RpcReachabilityDelegate interface { // A node has received a response ReachabilityDidReceiveNode(tester *RpcReachability, latency *RpcLatency) // A node request failed ReachabilityDidFailNode(tester *RpcReachability, latency *RpcLatency) // The entire network connection test task is over // @param overview Overview of the results of all connection tests ReachabilityDidFinish(tester *RpcReachability, overview string) }
type Token ¶ added in v0.2.0
type Token struct {
// contains filtered or unexported fields
}
func (*Token) BalanceOfAccount ¶ added in v0.2.0
func (*Token) BalanceOfAddress ¶ added in v0.2.0
func (*Token) BalanceOfPublicKey ¶ added in v0.2.0
func (*Token) BuildTransferTx ¶ added in v0.2.0
func (t *Token) BuildTransferTx(privateKey string, transaction *Transaction) (*base.OptionalString, error)
func (*Token) BuildTransferTxWithAccount ¶ added in v0.2.0
func (t *Token) BuildTransferTxWithAccount(account *Account, transaction *Transaction) (*base.OptionalString, error)
func (*Token) EstimateGasFeeLayer2 ¶ added in v0.2.5
func (t *Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
func (*Token) EstimateGasLimit ¶ added in v0.2.0
type TokenProtocol ¶ added in v0.2.0
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 ¶ added in v0.2.3
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 ¶ added in v0.2.3
func NewTransaction(nonce, gasPrice, gasLimit, to, value, data string) *Transaction
func NewTransactionFromHex ¶ added in v0.2.6
func NewTransactionFromHex(hexData string) (*Transaction, error)
func (*Transaction) GetRawTx ¶ added in v0.2.3
func (tx *Transaction) GetRawTx() (*types.Transaction, error)
func (*Transaction) MaxFee ¶ added in v0.2.3
func (tx *Transaction) MaxFee() string
This is an alias property for GasPrice in order to support EIP1559
func (*Transaction) SetMaxFee ¶ added in v0.2.3
func (tx *Transaction) SetMaxFee(maxFee string)
This is an alias property for GasPrice in order to support EIP1559
func (*Transaction) TotalAmount ¶ added in v0.2.6
func (tx *Transaction) TotalAmount() string
@return gasPrice * gasLimit + value
func (*Transaction) TransformToErc20Transaction ¶ added in v0.2.3
func (tx *Transaction) TransformToErc20Transaction(contractAddress string) error
type TransactionByHashResult ¶
type Util ¶ added in v0.2.0
type Util struct { }
func (*Util) DecodeAddressToPublicKey ¶ added in v0.2.0
Warning: eth cannot support decode address to public key
func (*Util) EncodePublicKeyToAddress ¶ added in v0.2.0
func (*Util) IsValidAddress ¶ added in v0.2.0
Check if address is 40 hexadecimal characters
Source Files ¶
- account.go
- address_util.go
- chain.go
- chainManager.go
- chain_gas.go
- chain_other.go
- coin.go
- constants.go
- erc20token.go
- eth_common.go
- ethchain.go
- ethchain_basic.go
- ethchain_erc20.go
- ethchain_gas.go
- ethchain_sign.go
- ethchain_transactionDetail.go
- ethchain_tx.go
- red_packet.go
- rpc_reachability.go
- token.go
- types.go
- utils.go