types

package
v0.0.0-...-5597975 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 5 Imported by: 0

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

func MustParseAddress(s string) Address

MustParseAddress is like ParseAddress but panics on error.

func ParseAddress

func ParseAddress(s string) (Address, error)

ParseAddress parses and validates an Ethereum address string.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns the address as a 20-byte slice.

func (Address) IsZero

func (a Address) IsZero() bool

IsZero returns true if the address is the zero address or empty.

func (Address) MarshalJSON

func (a Address) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Address) String

func (a Address) String() string

String returns the hex string representation of the address.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

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

func (b *Block) TransactionCount() int

TransactionCount returns the number of transactions in the block.

func (*Block) TransactionHashes

func (b *Block) TransactionHashes() []Hash

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

func (b *Block) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Data

type Data string

Data represents arbitrary hex-encoded data.

func DataFromBytes

func DataFromBytes(b []byte) Data

DataFromBytes creates Data from bytes.

func (Data) Bytes

func (d Data) Bytes() []byte

Bytes returns the data as bytes.

func (Data) MarshalJSON

func (d Data) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Data) String

func (d Data) String() string

String returns the hex string representation.

func (*Data) UnmarshalJSON

func (d *Data) UnmarshalJSON(data []byte) error

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

func MustParseHash(s string) Hash

MustParseHash is like ParseHash but panics on error.

func ParseHash

func ParseHash(s string) (Hash, error)

ParseHash parses and validates an Ethereum hash string.

func (Hash) Bytes

func (h Hash) Bytes() []byte

Bytes returns the hash as a 32-byte slice.

func (Hash) IsZero

func (h Hash) IsZero() bool

IsZero returns true if the hash is the zero hash or empty.

func (Hash) MarshalJSON

func (h Hash) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Hash) String

func (h Hash) String() string

String returns the hex string representation of the hash.

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

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

func (l *Log) Topic0() Hash

Topic0 returns the first topic (event signature), or empty hash if not present.

func (*Log) Topic1

func (l *Log) Topic1() Hash

Topic1 returns the second topic, or empty hash if not present.

func (*Log) Topic2

func (l *Log) Topic2() Hash

Topic2 returns the third topic, or empty hash if not present.

func (*Log) Topic3

func (l *Log) Topic3() Hash

Topic3 returns the fourth topic, 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

func QuantityFromBigInt(n *big.Int) Quantity

QuantityFromBigInt creates a Quantity from a *big.Int.

func QuantityFromUint64

func QuantityFromUint64(n uint64) Quantity

QuantityFromUint64 creates a Quantity from a uint64.

func (Quantity) BigInt

func (q Quantity) BigInt() *big.Int

BigInt returns the quantity as *big.Int.

func (Quantity) Int64

func (q Quantity) Int64() int64

Int64 returns the quantity as int64.

func (Quantity) IsZero

func (q Quantity) IsZero() bool

IsZero returns true if the quantity is zero or empty.

func (Quantity) MarshalJSON

func (q Quantity) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Quantity) String

func (q Quantity) String() string

String returns the hex string representation.

func (Quantity) Uint64

func (q Quantity) Uint64() uint64

Uint64 returns the quantity as uint64.

func (*Quantity) UnmarshalJSON

func (q *Quantity) UnmarshalJSON(data []byte) error

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL