Documentation
¶
Index ¶
- Constants
- type Account
- func (a *Account) AsContract() (*Contract, error)
- func (a *Account) ClearCache()
- func (a *Account) GetAddress() common.Address
- func (a *Account) GetBalance() common.BigInt
- func (a *Account) GetBalanceForce() (common.BigInt, error)
- func (a *Account) GetTransactions() (common.Transactions, error)
- func (a *Account) GetType() AccountType
- func (a *Account) IsContract() bool
- func (a *Account) UpdateBalance() bool
- type AccountType
- type ChainData
- type Contract
- func (c *Contract) Call(method string, args ...any) ([]any, error)
- func (c *Contract) GetABI() *abi.ABI
- func (c *Contract) GetSource() string
- func (c *Contract) HasABI() bool
- func (c *Contract) ImportABI(abiJson string) error
- func (c *Contract) ParseCalldata(data []byte) (*abi.Method, []any, error)
- func (c *Contract) Send(signer *Signer, method string, args ...any) (common.Hash, error)
- type Network
- type Service
- func (s *Service) GetAccount(address string) (*Account, error)
- func (s *Service) GetBlockHeight() (uint64, error)
- func (s *Service) GetCache(address common.Address, accountType AccountType) (any, bool)
- func (s *Service) GetContract(address common.Address) (*Contract, error)
- func (s *Service) GetEthPrice() (*decimal.Decimal, error)
- func (s *Service) GetGasPrice() (common.BigInt, error)
- func (s *Service) GetLatestTransactions(n int, nBlock int) (common.Transactions, error)
- func (s *Service) GetNetwork() Network
- func (s *Service) GetProvider() *provider.Provider
- func (s *Service) GetSigner(privateKey string) (*Signer, error)
- func (s *Service) GetTransactionHistory(address common.Address) (common.Transactions, error)
- func (s *Service) GetTransactionsByBlock(block *common.Block) (common.Transactions, error)
- func (s *Service) SetCache(address common.Address, accountType AccountType, value any, ...)
- func (s *Service) ToContract(account *Account) (*Contract, error)
- type Signer
- type Syncer
Constants ¶
const ( // TopicNewBlock is the topic about received new blocks TopicNewBlock = "service:newBlock" // TopicChainData is the topic about latest chain data (ether price, gas price, etc.) TopicChainData = "service:chainData" // TopicTick is a topic that receives tick event periodically TopicTick = "service:tick" // UpdatePeriod is the time duration between two updates UpdatePeriod = 10 * time.Second )
const ( // TypeMainnet is the Ethereum Mainnet TypeMainnet = "mainnet" // TypeTestnet is all kinds of the testnets (Ropsten, Rinkeby, Goerli etc.) TypeTestnet = "testnet" // TypeDevnet is a local network for development purpose (Hardhat, Ganeche etc.) TypeDevnet = "devnet" // TypeUnknown is a unknown network TypeUnknown = "unknown" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
// contains filtered or unexported fields
}
Account represents an account of Etheruem network.
func (*Account) AsContract ¶
AsContract upgrade this account object to a contract.
func (*Account) ClearCache ¶ added in v0.2.0
func (a *Account) ClearCache()
ClearCache will clear cached balance
func (*Account) GetAddress ¶
GetAddress returns address of this account.
func (*Account) GetBalance ¶
GetBalance returns cached balance of this account.
func (*Account) GetBalanceForce ¶
GetBalanceForce will query for current account's balance, store it in cache and return.
func (*Account) GetTransactions ¶
func (a *Account) GetTransactions() (common.Transactions, error)
GetTransactions returns transactions of this account.
func (*Account) GetType ¶
func (a *Account) GetType() AccountType
GetType returns type of this account, either Wallet or Contract.
func (*Account) IsContract ¶
IsContract returns true if this account is a smart contract.
func (*Account) UpdateBalance ¶
UpdateBalance will update cache of current account's balance
type AccountType ¶
type AccountType string
AccountType represents two types of Etheruem's account: EOA and SmartContract.
const ( // TypeWallet is an EOA account. TypeWallet AccountType = "Wallet" // TypeContract is a SmartContract account. TypeContract = "Contract" )
func (AccountType) String ¶
func (at AccountType) String() string
type Contract ¶
type Contract struct { *Account // contains filtered or unexported fields }
Contract represents a smart contract deployed on Ethereum network.
func (*Contract) Call ¶
Call invokes a constant method of this contract. The arguments should be unpacked into correct type.
func (*Contract) GetSource ¶
GetSource returns source of this contract, may be empty if source cannot be retrieved.
func (*Contract) ParseCalldata ¶ added in v0.2.0
ParseCalldata parses calldata into method name and arguments.
type Network ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) GetAccount ¶
GetAccount returns an account of given address.
func (*Service) GetBlockHeight ¶
GetBlockHeight returns the current block height.
func (*Service) GetContract ¶
GetContract returns a contract object of given address.
func (*Service) GetEthPrice ¶
GetEthPrice returns ETH price in USD.
func (*Service) GetGasPrice ¶
GetGasPrice returns average gas price of last block.
func (*Service) GetLatestTransactions ¶
GetLatestTransactions returns last n transactions of at most nBlock blocks.
func (*Service) GetNetwork ¶
GetNetwork returns the network that provider is connected to.
func (*Service) GetProvider ¶
GetProvider returns underlying provider instance. Usually you don't need to tackle with provider directly.
func (*Service) GetTransactionHistory ¶
GetTransactionHistory returns transactions related to specified account. This method relies on Etherscan API at chains other than local chain.
func (*Service) GetTransactionsByBlock ¶
GetTransactionsByBlock returns transactions of given block hash.
type Signer ¶
type Signer struct { *Account PrivateKey *ecdsa.PrivateKey }