Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeAddressToPublicKey(address string) (string, error)
- func DecodeContractParams(abiString string, data []byte) (string, []interface{}, error)
- func EncodeContractData(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 IsValidSignature(publicKey, msg, signature []byte) bool
- func PrivateKeyToAddress(privateKey string) (string, error)
- func SignHashForMsg(data string) []byte
- func ToChecksumAddress(address string) string
- func TransformEIP55Address(address string) string
- 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) SignHash(hash []byte) ([]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) EnsureApprovedTokens(account *Account, spender string, coins int, tokenAddress string, ...) (string, error)
- func (c *Chain) Erc20Token(contractAddress string) TokenProtocol
- func (c *Chain) EstimateGasLimit(msg *CallMsg) (gas *base.OptionalString, err error)
- func (c *Chain) EstimateTransactionFee(transaction base.Transaction) (fee *base.OptionalString, err error)
- func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction, pubkey string) (fee *base.OptionalString, err error)
- func (c *Chain) FetchRedPacketCreationDetail(hash string) (*RedPacketDetail, error)
- func (c *Chain) FetchTransactionDetail(hash string) (*base.TransactionDetail, error)
- func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus
- func (c *Chain) GetEthChain() (*EthChain, error)
- 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) SendSignedTransaction(signedTxn base.SignedTransaction) (hash *base.OptionalString, err 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) SubmitTransactionData(account base.Account, to string, data []byte, value string) (string, error)
- func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)
- func (c *Chain) SuggestGasPriceEIP1559() (*GasPrice, error)
- type ContractInfo
- type Contracts
- 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) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)
- func (t *Erc20Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err 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) CanTransferAll() bool
- 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, txn *types.Transaction, 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 IChain
- type Jsonable
- type OptimismLayer2Gas
- type RSS3Fetcher
- type RSS3Metadata
- type RSS3Note
- type RSS3NoteAction
- type Receipt
- type RedPacketAction
- func NewRedPacketActionClose(packetId int64, creator string) (*RedPacketAction, error)deprecated
- func NewRedPacketActionCreate(erc20TokenAddress string, count int, amount string) (*RedPacketAction, error)deprecated
- func NewRedPacketActionOpen(packetId int64, addresses []string, amounts []string) (*RedPacketAction, error)deprecated
- func (rpa *RedPacketAction) EnsureApprovedTokens(account *Account, chain *Chain, spender string, coins int) (string, error)deprecated
- func (rpa *RedPacketAction) EstimateAmount() string
- func (rpa *RedPacketAction) TransactionFrom(fromAddress, contractAddress string, chain *Chain) (*Transaction, error)deprecated
- type RedPacketDetaildeprecated
- type RpcConfig
- type RpcInfo
- type RpcReachability
- 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) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)
- func (t *Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err 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) CanTransferAll() bool
- 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
- func (tx *Transaction) GetRawTx() (*types.Transaction, error)
- func (tx *Transaction) MaxFee() string
- func (tx *Transaction) SetMaxFee(maxFee string)
- func (t *Transaction) SignWithAccount(account base.Account) (signedTx *base.OptionalString, err error)
- func (t *Transaction) SignedTransactionWithAccount(account base.Account) (signedTx base.SignedTransaction, err error)
- func (tx *Transaction) TotalAmount() string
- func (tx *Transaction) TransformToErc20Transaction(contractAddress string) error
- 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 ( NetworkNameEthereum = "ethereum" NetworkNameBSC = "binance_smart_chain" NetworkNamePolygon = "polygon" NetworkNameArbitrum = "arbitrum" NetworkNameOptimism = "optimism" NetworkNameAvalanche = "avalanche" TagCollectible = "collectible" )
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 ¶
var Rpcs = RpcConfig{ // contains filtered or unexported fields }
Functions ¶
func DecodeAddressToPublicKey ¶
Warning: eth cannot support decode address to public key
func DecodeContractParams ¶
func EncodeContractData ¶
func EncodeErc20Transfer ¶
Encode erc20 transfer data
func IsValidAddress ¶
Check if address is 40 hexadecimal characters
func IsValidEIP55Address ¶
It will check based on eip55 rules
func IsValidSignature ¶
func ToChecksumAddress ¶
ToChecksumAddress 将以太坊地址从不区分大小写转换为区分大小写
func TransformEIP55Address ¶
func VerifySignature ¶
Types ¶
type Account ¶
type Account struct { *Util // contains filtered or unexported fields }
func AccountWithPrivateKey ¶
func AsEthereumAccount ¶
func EthAccountWithPrivateKey ¶
We cannot use name `NewAccountWithPrivateKey`, because android not support.
func NewAccountWithMnemonic ¶
func (*Account) PrivateKeyHex ¶
@return privateKey string that will start with 0x.
func (*Account) PublicKeyHex ¶
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 ¶
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) GetDataHex ¶
func (*CallMsg) GetGasLimit ¶
func (*CallMsg) GetGasPrice ¶
func (*CallMsg) SetDataHex ¶
func (*CallMsg) SetGasLimit ¶
func (*CallMsg) SetGasPrice ¶
func (*CallMsg) SetValueHex ¶
Set amount with hexadecimal number
func (*CallMsg) TransferToTransaction ¶
func (msg *CallMsg) TransferToTransaction() *Transaction
type Chain ¶
type Chain struct {
RpcUrl string
}
func NewChainWithRpc ¶
func (*Chain) BalanceOfAccount ¶
func (*Chain) BalanceOfAddress ¶
func (*Chain) BalanceOfPublicKey ¶
func (*Chain) BatchErc20TokenBalance ¶
批量请求代币余额 @param contractList 批量查询的代币的合约地址数组 @param address 用户的钱包地址 @return 余额数组,顺序与传入的 contractList 是保持一致的 @throw 如果任意一个代币请求余额出错时,会抛出错误
func (*Chain) BatchFetchErc20TokenBalance ¶
SDK 批量请求代币余额,因为 golang 导出的方法不支持数组,因此传参和返回都只能用字符串 @param contractListString 批量查询的代币的合约地址字符串,用逗号隔开,例如: "add1,add2,add3" @param address 用户的钱包地址 @return 余额列表,顺序与传入合约顺序是保持一致的,例如: "b1,b2,b3" @throw 如果任意一个代币请求余额出错时,会抛出错误
func (*Chain) BatchFetchTransactionStatus ¶
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 ¶
call eth_call method @param blockNumber Especially -2 is the latest block, -1 is pending block.
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 (*Chain) LatestBlockNumber ¶
func (*Chain) MainEthToken ¶
func (c *Chain) MainEthToken() TokenProtocol
func (*Chain) NonceOfAddress ¶
获取交易的 nonce
func (*Chain) PendingCallContract ¶
func (*Chain) SendRawTransaction ¶
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 (*Chain) SuggestGasPrice ¶
func (c *Chain) SuggestGasPrice() (*base.OptionalString, error)
func (*Chain) SuggestGasPriceEIP1559 ¶
The gas price use average grade default.
type ContractInfo ¶
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 ¶
type Erc20Token ¶
func NewErc20Token ¶
func NewErc20Token(chain *Chain, contractAddress string) *Erc20Token
func (*Erc20Token) Allowance ¶
func (t *Erc20Token) Allowance(owner, spender string) (*big.Int, 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)
type Erc20TokenInfo ¶
type Erc20TxParams ¶
type EthChain ¶
type EthChain struct { RemoteRpcClient *ethclient.Client RpcClient *rpc.Client // contains filtered or unexported fields }
func NewEthChain ¶
func NewEthChain() *EthChain
func (*EthChain) Balance ¶
Balance @title 主网代币余额查询 @description 返回主网代币余额,decimal为代币精度 @param (walletAddress) (string) 合约名称,钱包地址 @return (string,error) 代币余额,错误信息
func (*EthChain) BatchTransactionStatus ¶
批量获取交易的转账状态 @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 ¶
func (*EthChain) CreateRemote ¶
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) MethodFromPayload ¶
func (*EthChain) MethodIdFromMethodStr ¶
func (*EthChain) PackParams ¶
不带 0x 前缀
func (*EthChain) RecoverSignerAddress ¶
func (*EthChain) RecoverSignerAddressFromMsgHash ¶
func (*EthChain) SdkBatchTokenBalance
deprecated
func (*EthChain) SdkBatchTransactionStatus ¶
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)
SignTransaction @title SignTransaction @description 对交易进行签名 @param (tx, privateKey) (*types.Transaction,string) 合约名称,钱包地址 @return (*BuildTxResult,error) 签名结果,失败
func (*EthChain) TokenBalance ¶
TokenBalance @title Erc20代币余额 @description 返回erc20代币余额 @param (contractAddress,walletAddress) 合约地址,钱包地址 @return (string,error) 余额,错误信息
func (*EthChain) TokenDecimal ¶
TokenDecimal @title Erc20代币精度 @description 返回代币精度 @param (contractAddress) 合约地址 @return (string,error) 代币精度,错误信息
func (*EthChain) TokenName ¶
TokenName @title Erc20代币名称 @description 返回代币名称 @param (contractAddress) 合约地址 @return (string,error) 名称,错误信息
func (*EthChain) TokenSymbol ¶
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 ¶
TransactionReceipt 是指交易的收据,每笔交易执行完 会产生一个收据,收据中包含交易的状态,交易的gas使用情况,交易执行是否成功的状态码等信息 交易收据属性列表: gasUsed: 交易执行时使用的gas数量 bloomFilter:交易信息日志检索 logInfoList: 交易日志集合 postTxState: 交易执行后的状态,1 表示成功,0表示失败
func (*EthChain) UnpackParams ¶
type GasPrice ¶
type GasPrice struct { // Pending block baseFee in wei. BaseFee string SuggestPriorityFee string MaxPriorityFee string MaxFee string }
func (*GasPrice) UseAverage ¶
MaxPriorityFee = SuggestPriorityFee * 1.5 MaxFee = (MaxPriorityFee + BaseFee) * 1.11
func (*GasPrice) UseHigh ¶
MaxPriorityFee = SuggestPriorityFee * 2.0 MaxFee = (MaxPriorityFee + BaseFee) * 1.5
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) 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 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 ¶
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 RpcInfo ¶
type RpcInfo struct { ChainId string Url string Contracts *Contracts // contains filtered or unexported fields }
func GetRpcInfoByChainId ¶
GetRpcInfoByChainId 根据chainId返回对应的RpcInfo
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 (*Token) BalanceOfAccount ¶
func (*Token) BalanceOfAddress ¶
func (*Token) BalanceOfPublicKey ¶
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 (*Token) EstimateGasFeeLayer2 ¶
func (t *Token) EstimateGasFeeLayer2(msg *CallMsg) (*OptimismLayer2Gas, error)
func (*Token) EstimateGasLimit ¶
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 Util ¶
type Util struct { }
func (*Util) DecodeAddressToPublicKey ¶
Warning: eth cannot support decode address to public key
func (*Util) EncodePublicKeyToAddress ¶
func (*Util) IsValidAddress ¶
Check if address is 40 hexadecimal characters
Source Files ¶
- account.go
- address_util.go
- chain.go
- chainManager.go
- chain_gas.go
- chain_other.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
- ethchain_zksync.go
- nft.go
- red_packet.go
- rpc_config.go
- rpc_reachability.go
- token.go
- types.go
- utils.go