Documentation
¶
Overview ¶
Package types provides common types used across the Alchemy SDK.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessListEntry ¶
type AccessListEntry struct {
// Address is the accessed address.
Address Address `json:"address"`
// StorageKeys is the list of accessed storage keys.
StorageKeys []Hash `json:"storageKeys"`
}
AccessListEntry represents an entry in an access list.
type Address ¶
type Address string
Address represents an Ethereum address (20 bytes).
const ZeroAddress Address = "0x0000000000000000000000000000000000000000"
ZeroAddress is the zero address.
func MustParseAddress ¶
MustParseAddress is like ParseAddress but panics on error.
func ParseAddress ¶
ParseAddress parses and validates an Ethereum address string.
func (Address) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Block ¶
type Block struct {
// Hash is the block hash.
Hash Hash `json:"hash"`
// ParentHash is the parent block hash.
ParentHash Hash `json:"parentHash"`
// Sha3Uncles is the SHA3 of the uncles data in the block.
Sha3Uncles Hash `json:"sha3Uncles"`
// Miner is the address of the miner.
Miner Address `json:"miner"`
// StateRoot is the root of the state trie.
StateRoot Hash `json:"stateRoot"`
// TransactionsRoot is the root of the transaction trie.
TransactionsRoot Hash `json:"transactionsRoot"`
// ReceiptsRoot is the root of the receipts trie.
ReceiptsRoot Hash `json:"receiptsRoot"`
// LogsBloom is the bloom filter for logs.
LogsBloom Data `json:"logsBloom"`
// Difficulty is the difficulty of the block.
Difficulty Quantity `json:"difficulty,omitempty"`
// TotalDifficulty is the total difficulty of the chain until this block.
TotalDifficulty Quantity `json:"totalDifficulty,omitempty"`
// Number is the block number.
Number Quantity `json:"number"`
// GasLimit is the gas limit for the block.
GasLimit Quantity `json:"gasLimit"`
// GasUsed is the gas used by all transactions in the block.
GasUsed Quantity `json:"gasUsed"`
// Timestamp is the block timestamp.
Timestamp Quantity `json:"timestamp"`
// ExtraData is the extra data field of the block.
ExtraData Data `json:"extraData"`
// MixHash is the mix hash.
MixHash Hash `json:"mixHash"`
// Nonce is the block nonce.
Nonce Data `json:"nonce"`
// BaseFeePerGas is the base fee per gas (EIP-1559).
BaseFeePerGas *Quantity `json:"baseFeePerGas,omitempty"`
// WithdrawalsRoot is the root of the withdrawals trie (Shanghai upgrade).
WithdrawalsRoot *Hash `json:"withdrawalsRoot,omitempty"`
// BlobGasUsed is the blob gas used (EIP-4844).
BlobGasUsed *Quantity `json:"blobGasUsed,omitempty"`
// ExcessBlobGas is the excess blob gas (EIP-4844).
ExcessBlobGas *Quantity `json:"excessBlobGas,omitempty"`
// ParentBeaconBlockRoot is the parent beacon block root.
ParentBeaconBlockRoot *Hash `json:"parentBeaconBlockRoot,omitempty"`
// Size is the block size in bytes.
Size Quantity `json:"size"`
// Uncles is the list of uncle block hashes.
Uncles []Hash `json:"uncles"`
// Withdrawals is the list of withdrawals (Shanghai upgrade).
Withdrawals []Withdrawal `json:"withdrawals,omitempty"`
// contains filtered or unexported fields
}
Block represents an Ethereum block.
func (*Block) TransactionCount ¶
TransactionCount returns the number of transactions in the block.
func (*Block) TransactionHashes ¶
TransactionHashes returns the transaction hashes if the block was fetched without full transactions. Returns nil if the block contains full transaction objects.
func (*Block) Transactions ¶
func (b *Block) Transactions() []Transaction
Transactions returns the full transactions if the block was fetched with full transactions. Returns nil if the block only contains transaction hashes.
func (*Block) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Data ¶
type Data string
Data represents arbitrary hex-encoded data.
func (Data) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Data) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Hash ¶
type Hash string
Hash represents an Ethereum hash (32 bytes).
const ZeroHash Hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
ZeroHash is the zero hash.
func MustParseHash ¶
MustParseHash is like ParseHash but panics on error.
func (Hash) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Hash) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Log ¶
type Log struct {
// Address is the contract address that emitted the log.
Address Address `json:"address"`
// Topics is the list of topics (indexed parameters).
Topics []Hash `json:"topics"`
// Data is the non-indexed log data.
Data Data `json:"data"`
// BlockNumber is the block number where the log was emitted.
BlockNumber Quantity `json:"blockNumber"`
// TransactionHash is the transaction hash.
TransactionHash Hash `json:"transactionHash"`
// TransactionIndex is the transaction index in the block.
TransactionIndex Quantity `json:"transactionIndex"`
// BlockHash is the block hash.
BlockHash Hash `json:"blockHash"`
// LogIndex is the log index in the block.
LogIndex Quantity `json:"logIndex"`
// Removed is true if the log was reverted due to a chain reorganization.
Removed bool `json:"removed"`
}
Log represents an Ethereum log entry.
func (*Log) Topic0 ¶
Topic0 returns the first topic (event signature), or empty hash if not present.
type Quantity ¶
type Quantity string
Quantity represents a hex-encoded quantity (used for numbers in JSON-RPC).
func QuantityFromBigInt ¶
QuantityFromBigInt creates a Quantity from a *big.Int.
func QuantityFromUint64 ¶
QuantityFromUint64 creates a Quantity from a uint64.
func (Quantity) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Quantity) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Transaction ¶
type Transaction struct {
// Hash is the transaction hash.
Hash Hash `json:"hash"`
// Nonce is the sender's nonce.
Nonce Quantity `json:"nonce"`
// BlockHash is the block hash (null for pending transactions).
BlockHash *Hash `json:"blockHash,omitempty"`
// BlockNumber is the block number (null for pending transactions).
BlockNumber *Quantity `json:"blockNumber,omitempty"`
// TransactionIndex is the transaction index in the block (null for pending).
TransactionIndex *Quantity `json:"transactionIndex,omitempty"`
// From is the sender address.
From Address `json:"from"`
// To is the recipient address (null for contract creation).
To *Address `json:"to,omitempty"`
// Value is the value transferred in wei.
Value Quantity `json:"value"`
// Gas is the gas limit.
Gas Quantity `json:"gas"`
// GasPrice is the gas price (legacy and EIP-2930 transactions).
GasPrice *Quantity `json:"gasPrice,omitempty"`
// MaxFeePerGas is the max fee per gas (EIP-1559 transactions).
MaxFeePerGas *Quantity `json:"maxFeePerGas,omitempty"`
// MaxPriorityFeePerGas is the max priority fee per gas (EIP-1559 transactions).
MaxPriorityFeePerGas *Quantity `json:"maxPriorityFeePerGas,omitempty"`
// MaxFeePerBlobGas is the max fee per blob gas (EIP-4844 transactions).
MaxFeePerBlobGas *Quantity `json:"maxFeePerBlobGas,omitempty"`
// Input is the transaction input data.
Input Data `json:"input"`
// V is the recovery id.
V Quantity `json:"v"`
// R is the signature r value.
R Quantity `json:"r"`
// S is the signature s value.
S Quantity `json:"s"`
// YParity is the y-parity of the signature (EIP-1559 and later).
YParity *Quantity `json:"yParity,omitempty"`
// Type is the transaction type.
Type *Quantity `json:"type,omitempty"`
// ChainID is the chain ID.
ChainID *Quantity `json:"chainId,omitempty"`
// AccessList is the access list (EIP-2930 and later).
AccessList []AccessListEntry `json:"accessList,omitempty"`
// BlobVersionedHashes is the blob versioned hashes (EIP-4844).
BlobVersionedHashes []Hash `json:"blobVersionedHashes,omitempty"`
}
Transaction represents an Ethereum transaction.
func (*Transaction) IsAccessList ¶
func (tx *Transaction) IsAccessList() bool
IsAccessList returns true if this is an access list (type 1) transaction.
func (*Transaction) IsBlob ¶
func (tx *Transaction) IsBlob() bool
IsBlob returns true if this is a blob (type 3) transaction.
func (*Transaction) IsDynamicFee ¶
func (tx *Transaction) IsDynamicFee() bool
IsDynamicFee returns true if this is a dynamic fee (type 2) transaction.
func (*Transaction) IsLegacy ¶
func (tx *Transaction) IsLegacy() bool
IsLegacy returns true if this is a legacy (type 0) transaction.
func (*Transaction) TxType ¶
func (tx *Transaction) TxType() int
TxType returns the transaction type as an integer.
type TransactionReceipt ¶
type TransactionReceipt struct {
// TransactionHash is the transaction hash.
TransactionHash Hash `json:"transactionHash"`
// TransactionIndex is the transaction index in the block.
TransactionIndex Quantity `json:"transactionIndex"`
// BlockHash is the block hash.
BlockHash Hash `json:"blockHash"`
// BlockNumber is the block number.
BlockNumber Quantity `json:"blockNumber"`
// From is the sender address.
From Address `json:"from"`
// To is the recipient address (null for contract creation).
To *Address `json:"to,omitempty"`
// CumulativeGasUsed is the cumulative gas used in the block up to this transaction.
CumulativeGasUsed Quantity `json:"cumulativeGasUsed"`
// GasUsed is the gas used by this transaction.
GasUsed Quantity `json:"gasUsed"`
// EffectiveGasPrice is the effective gas price (EIP-1559).
EffectiveGasPrice Quantity `json:"effectiveGasPrice"`
// ContractAddress is the contract address created (if any).
ContractAddress *Address `json:"contractAddress,omitempty"`
// Logs is the list of logs emitted by the transaction.
Logs []Log `json:"logs"`
// LogsBloom is the bloom filter for logs.
LogsBloom Data `json:"logsBloom"`
// Type is the transaction type.
Type Quantity `json:"type"`
// Status is the transaction status (1 = success, 0 = failure).
Status Quantity `json:"status"`
// Root is the post-transaction state root (pre-Byzantium only).
Root *Hash `json:"root,omitempty"`
// BlobGasUsed is the blob gas used (EIP-4844).
BlobGasUsed *Quantity `json:"blobGasUsed,omitempty"`
// BlobGasPrice is the blob gas price (EIP-4844).
BlobGasPrice *Quantity `json:"blobGasPrice,omitempty"`
}
TransactionReceipt represents an Ethereum transaction receipt.
func (*TransactionReceipt) IsContractCreation ¶
func (r *TransactionReceipt) IsContractCreation() bool
IsContractCreation returns true if the transaction created a contract.
func (*TransactionReceipt) IsFailed ¶
func (r *TransactionReceipt) IsFailed() bool
IsFailed returns true if the transaction failed.
func (*TransactionReceipt) IsSuccessful ¶
func (r *TransactionReceipt) IsSuccessful() bool
IsSuccessful returns true if the transaction was successful.
type Withdrawal ¶
type Withdrawal struct {
// Index is the withdrawal index.
Index Quantity `json:"index"`
// ValidatorIndex is the validator index.
ValidatorIndex Quantity `json:"validatorIndex"`
// Address is the recipient address.
Address Address `json:"address"`
// Amount is the amount in Gwei.
Amount Quantity `json:"amount"`
}
Withdrawal represents a validator withdrawal (Shanghai upgrade).