Documentation
¶
Overview ¶
Request info from blockscan.
Example:
// To get the balance of address "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7" scanner, err:=blockscan.New("avalanche","") if err != nil { return err } res, err := scanner.GetBalance("0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7") if err != nil { return err } fmt.Println(res)
Index ¶
- type AbiInput
- type AbiOutput
- type ContractAbi
- type Scanner
- func (s *Scanner) GetBalance(address any) (*big.Int, error)
- func (s *Scanner) GetBalances(addresses []string) (map[string]*big.Int, error)
- func (s *Scanner) GetBlockNumberByTimestamp(timestamp string) (int64, error)
- func (s *Scanner) GetContractAbi(address any) (ContractAbi, error)
- func (s *Scanner) GetContractName(address any) (string, error)
- func (s *Scanner) GetErc20Transactions(address any, startBlock int, endBlock any) ([]erc20Txs, error)
- func (s *Scanner) GetErc20TransactionsAll(address any) ([]erc20Txs, error)
- func (s *Scanner) GetEvents(topic0 string, address any, startBlock int, endBlock any) ([]events, error)
- func (s *Scanner) GetEventsAll(topic0 string, address string) ([]events, error)
- func (s *Scanner) GetGasPrice() (*big.Int, error)
- func (s *Scanner) GetInternalTransactions(address any, startBlock int, endBlock any) ([]internalTxs, error)
- func (s *Scanner) GetInternalTransactionsAll(address any) ([]internalTxs, error)
- func (s *Scanner) GetNormalTransactions(address any, startBlock int, endBlock any) ([]normalTxs, error)
- func (s *Scanner) GetNormalTransactionsAll(address any) ([]normalTxs, error)
- func (s *Scanner) GetSourceCode(address any) (sourceCode, error)
- func (s *Scanner) IsVerifiedContract(address any) (bool, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContractAbi ¶ added in v0.4.0
type Scanner ¶ added in v0.2.0
type Scanner struct { UrlHead string // Url head based on network. ApiKey string // User's api key, length should be 34. }
func New ¶ added in v0.2.0
Create a new scanner.
"network" should be the full name of the chain, such as "ethereum", "avalanche", etc.
"apiKey" is the key for blockscan requests. When the key is "", default key will be used. Otherwise, the key length should be 34.
To get an apikey on ethereum, visit https://docs.etherscan.io/getting-started/viewing-api-usage-statistics
Example ¶
// case 1 fmt.Println("\ncase 1:") scanner, err := New(chainId.AvalancheChainName, "") if err != nil { fmt.Println(err) } else { fmt.Println(*scanner) } // case 2, wrong key fmt.Println("\ncase 2:") scanner, err = New(chainId.AvalancheChainName, "asaasfas") if err != nil { fmt.Println(err) } else { fmt.Println(*scanner) }
Output: case 1: You do not have a blockscan api key. Unecpected errors may occur when running. {https://api.snowtrace.io/api? K6SR1G96B2SQBRWPI4JP8WXM6BCG62EPQ7} case 2: api key length should be 34
func (*Scanner) GetBalance ¶ added in v0.2.0
Return the balance of a single address.
func (*Scanner) GetBalances ¶ added in v0.2.0
Return balances of up to 20 addresses. map[address] = balance.
func (*Scanner) GetBlockNumberByTimestamp ¶ added in v0.2.0
Return the block number.
func (*Scanner) GetContractAbi ¶ added in v0.2.0
func (s *Scanner) GetContractAbi(address any) (ContractAbi, error)
Return the contract's abi.
func (*Scanner) GetContractName ¶ added in v0.2.0
Return the contract's name.
func (*Scanner) GetErc20Transactions ¶ added in v0.2.0
func (s *Scanner) GetErc20Transactions(address any, startBlock int, endBlock any) ([]erc20Txs, error)
Return up to 10000 erc20 txs of an address.
func (*Scanner) GetErc20TransactionsAll ¶ added in v0.2.0
Return all the erc20 txs of an address.
func (*Scanner) GetEvents ¶ added in v0.2.0
func (s *Scanner) GetEvents(topic0 string, address any, startBlock int, endBlock any) ([]events, error)
Return up to 1000 events of an address.
Param:
topic0: The topic0 of the event. In most cases means the hash of the function name. address: The address. Can be string or common.Address startBlock: The block to start from. endBlock: The block to end. If greater than latest block number, or use "latest", will use the latest block number.
func (*Scanner) GetEventsAll ¶ added in v0.2.0
Return all the events of an address.
Param:
topic0: The topic0 of the event. In most cases means the hash of the function name. address: The address. Can be string or common.Address
func (*Scanner) GetGasPrice ¶ added in v0.2.0
Return gas price in WEI.
func (*Scanner) GetInternalTransactions ¶ added in v0.2.0
func (s *Scanner) GetInternalTransactions(address any, startBlock int, endBlock any) ([]internalTxs, error)
Return up to 10000 internal txs of an address.
func (*Scanner) GetInternalTransactionsAll ¶ added in v0.2.0
Return all the internal txs of an address.
func (*Scanner) GetNormalTransactions ¶ added in v0.2.0
func (s *Scanner) GetNormalTransactions(address any, startBlock int, endBlock any) ([]normalTxs, error)
Return up to 10000 txs of an address.
func (*Scanner) GetNormalTransactionsAll ¶ added in v0.2.0
Return all the txs of an address.
func (*Scanner) GetSourceCode ¶ added in v0.2.0
Return the source code of a contract.