Documentation
¶
Index ¶
- Constants
- type AddressFilter
- type AlchemyClient
- func (a *AlchemyClient) Close() error
- func (a *AlchemyClient) SubscribeLogs(filter LogsFilter) (<-chan LogEvent, error)
- func (a *AlchemyClient) SubscribeMined(opts MinedTxOptions) (<-chan MinedTxEvent, error)
- func (a *AlchemyClient) SubscribeNewHeads() (<-chan NewHeadEvent, error)
- func (a *AlchemyClient) SubscribeNewPendingTransactions() (<-chan string, error)
- func (a *AlchemyClient) SubscribePending(opts PendingTxOptions) (<-chan PendingTxEvent, error)
- type LogEvent
- type LogsFilter
- type MinedTxEvent
- type MinedTxOptions
- type NewHeadEvent
- type PendingTxEvent
- type PendingTxOptions
- type Transaction
- type WSConn
Constants ¶
const ( AlchemyWSURL = "wss://eth-mainnet.g.alchemy.com/v2/" JSONRPCVersion = "2.0" MethodMined = "alchemy_minedTransactions" MethodPending = "alchemy_pendingTransactions" MethodNewHeads = "newHeads" MethodLogs = "logs" MethodNewPendingTransactions = "newPendingTransactions" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressFilter ¶
AddressFilter can filter transactions by sender and receiver addresses.
type AlchemyClient ¶
type AlchemyClient struct {
// contains filtered or unexported fields
}
func NewAlchemyClient ¶
func NewAlchemyClient(apiKey string, logger *log.Logger) (*AlchemyClient, error)
NewAlchemyClient connects to Alchemy's WebSocket API and starts a single read loop
func (*AlchemyClient) Close ¶
func (a *AlchemyClient) Close() error
Close shuts down the WebSocket connection
func (*AlchemyClient) SubscribeLogs ¶ added in v0.2.0
func (a *AlchemyClient) SubscribeLogs(filter LogsFilter) (<-chan LogEvent, error)
func (*AlchemyClient) SubscribeMined ¶
func (a *AlchemyClient) SubscribeMined(opts MinedTxOptions) (<-chan MinedTxEvent, error)
SubscribeMined subscribes to mined transactions
func (*AlchemyClient) SubscribeNewHeads ¶ added in v0.1.1
func (a *AlchemyClient) SubscribeNewHeads() (<-chan NewHeadEvent, error)
SubscribeNewHeads subscribes to new block headers added to the blockchain.
func (*AlchemyClient) SubscribeNewPendingTransactions ¶ added in v0.3.0
func (a *AlchemyClient) SubscribeNewPendingTransactions() (<-chan string, error)
SubscribeNewPendingTransactions subscribes to pending transaction hashes.
func (*AlchemyClient) SubscribePending ¶
func (a *AlchemyClient) SubscribePending(opts PendingTxOptions) (<-chan PendingTxEvent, error)
SubscribePending subscribes to pending transactions
type LogEvent ¶ added in v0.2.0
type LogEvent struct {
Address string `json:"address"`
BlockHash string `json:"blockHash"`
BlockNumber string `json:"blockNumber"`
Data string `json:"data"`
LogIndex string `json:"logIndex"`
Topics []string `json:"topics"`
TransactionHash string `json:"transactionHash"`
TransactionIndex string `json:"transactionIndex"`
Removed bool `json:"removed,omitempty"`
}
LogEvent represents a log emitted by the logs subscription.
type LogsFilter ¶ added in v0.2.0
type LogsFilter struct {
Address string `json:"address,omitempty"`
Topics [][]string `json:"topics,omitempty"` // can be null, string, or array of strings
}
LogsFilter represents the subscription filter for logs.
type MinedTxEvent ¶
type MinedTxEvent struct {
Removed bool `json:"removed"`
Transaction Transaction `json:"transaction,omitempty"`
Hash string `json:"hash,omitempty"`
}
MinedTxEvent wraps the transaction and removal status.
type MinedTxOptions ¶
type MinedTxOptions struct {
Addresses []AddressFilter `json:"addresses,omitempty"`
IncludeRemoved bool `json:"includeRemoved,omitempty"`
HashesOnly bool `json:"hashesOnly,omitempty"`
}
MinedTxOptions defines the parameters for the subscription request.
type NewHeadEvent ¶ added in v0.1.1
type NewHeadEvent struct {
Number string `json:"number"`
ParentHash string `json:"parentHash"`
Nonce string `json:"nonce"`
Sha3Uncles string `json:"sha3Uncles"`
LogsBloom string `json:"logsBloom"`
TransactionsRoot string `json:"transactionsRoot"`
StateRoot string `json:"stateRoot"`
ReceiptsRoot string `json:"receiptsRoot"`
Miner string `json:"miner"`
Difficulty string `json:"difficulty"`
ExtraData string `json:"extraData"`
GasLimit string `json:"gasLimit"`
GasUsed string `json:"gasUsed"`
Timestamp string `json:"timestamp"`
}
NewHeadEvent represents a new block header received via the newHeads subscription.
type PendingTxEvent ¶
type PendingTxEvent struct {
Transaction Transaction `json:"transaction,omitempty"`
Hash string `json:"hash,omitempty"`
}
PendingTxEvent represents either a full pending transaction or a hash depending on the HashesOnly flag in subscription.
type PendingTxOptions ¶
type PendingTxOptions struct {
FromAddress []string `json:"fromAddress,omitempty"`
ToAddress []string `json:"toAddress,omitempty"`
HashesOnly bool `json:"hashesOnly,omitempty"`
}
PendingTxOptions defines parameters for subscribing to pending transactions
type Transaction ¶
type Transaction struct {
BlockHash string `json:"blockHash"`
BlockNumber string `json:"blockNumber"`
From string `json:"from"`
Gas string `json:"gas"`
GasPrice string `json:"gasPrice"`
Hash string `json:"hash"`
Input string `json:"input"`
Nonce string `json:"nonce"`
To string `json:"to"`
TransactionIndex string `json:"transactionIndex"`
Value string `json:"value"`
V string `json:"v"`
R string `json:"r"`
S string `json:"s"`
Type string `json:"type"`
}
Transaction is the generic Ethereum transaction format for mined or pending When pending, many fields may be null.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
subscribe_logs
command
|
|
|
subscribe_mined_transactions
command
|
|
|
subscribe_new_heads
command
|
|
|
subscribe_pending_transactions
command
|