Documentation
¶
Overview ¶
Package alchemy provides a Golang SDK for the Alchemy API.
The SDK covers Node API (JSON-RPC), Data API (Transfers, NFTs, Tokens), and Wallet API for blockchain data access.
Example usage:
client, err := alchemy.New(alchemy.Config{
APIKey: os.Getenv("ALCHEMY_API_KEY"),
Network: alchemy.EthMainnet,
})
if err != nil {
log.Fatal(err)
}
// Get block number
blockNum, _ := client.Node.BlockNumber(ctx)
// Get asset transfers
transfers, _ := client.Data.GetAssetTransfers(ctx, &data.AssetTransfersParams{
ToAddress: &address,
Category: []data.AssetTransferCategory{data.CategoryERC20},
})
Index ¶
- Variables
- type Alchemy
- type Config
- type ConfigError
- type Network
- func (n Network) BaseURL() string
- func (n Network) ChainID() uint64
- func (n Network) IsEthereum() bool
- func (n Network) IsL2() bool
- func (n Network) IsMainnet() bool
- func (n Network) IsTestnet() bool
- func (n Network) NFTURL() string
- func (n Network) NativeCurrency() string
- func (n Network) String() string
Constants ¶
This section is empty.
Variables ¶
var (
ErrMissingAPIKey = &ConfigError{Message: "API key is required"}
)
Common configuration errors.
Functions ¶
This section is empty.
Types ¶
type Alchemy ¶
type Alchemy struct {
// Node provides access to JSON-RPC methods (eth_*, debug_*, etc.).
Node *node.Client
// Data provides access to enhanced data APIs (transfers, tokens, NFTs).
Data *data.Client
// Wallet provides high-level wallet operations.
Wallet *wallet.Client
// contains filtered or unexported fields
}
Alchemy is the main client for the Alchemy API.
type Config ¶
type Config struct {
// APIKey is the Alchemy API key (required).
APIKey string
// Network is the blockchain network to connect to (default: EthMainnet).
Network Network
// BaseURL overrides the default API endpoint.
// If empty, the endpoint is derived from Network.
BaseURL string
// Timeout is the request timeout (default: 30s).
Timeout time.Duration
// MaxRetries is the maximum number of retry attempts (default: 3).
MaxRetries int
// RetryDelay is the initial delay between retries (default: 1s).
RetryDelay time.Duration
// RetryMaxDelay is the maximum delay between retries (default: 30s).
RetryMaxDelay time.Duration
// HTTPClient is a custom HTTP client to use.
// If nil, a default client is created.
HTTPClient *http.Client
// Debug enables debug logging.
Debug bool
}
Config holds the configuration for the Alchemy client.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with default values.
func (*Config) GetBaseURL ¶
GetBaseURL returns the base URL for API requests.
func (*Config) GetHTTPClient ¶
GetHTTPClient returns the HTTP client to use.
func (Config) WithDefaults ¶
WithDefaults returns a copy of the config with default values applied for any zero-valued fields.
type ConfigError ¶
type ConfigError struct {
Message string
}
ConfigError represents a configuration error.
func (*ConfigError) Error ¶
func (e *ConfigError) Error() string
type Network ¶
type Network string
Network represents a blockchain network supported by Alchemy.
const ( EthMainnet Network = "eth-mainnet" EthSepolia Network = "eth-sepolia" EthHolesky Network = "eth-holesky" EthHoodi Network = "eth-hoodi" )
Ethereum networks.
Polygon networks.
const ( ArbitrumMainnet Network = "arb-mainnet" ArbitrumSepolia Network = "arb-sepolia" ArbitrumNova Network = "arbnova-mainnet" )
Arbitrum networks.
Optimism networks.
zkSync networks.
const ( PolygonZkEvmMainnet Network = "polygonzkevm-mainnet" PolygonZkEvmCardona Network = "polygonzkevm-cardona" )
Polygon zkEVM networks.
Linea networks.
Scroll networks.
Blast networks.
const ( AvalancheMainnet Network = "avax-mainnet" AvalancheFuji Network = "avax-fuji" BNBMainnet Network = "bnb-mainnet" BNBTestnet Network = "bnb-testnet" FantomMainnet Network = "fantom-mainnet" FantomTestnet Network = "fantom-testnet" GnosisMainnet Network = "gnosis-mainnet" GnosisChiado Network = "gnosis-chiado" CeloMainnet Network = "celo-mainnet" CeloAlfajores Network = "celo-alfajores" MantleMainnet Network = "mantle-mainnet" MantleSepolia Network = "mantle-sepolia" WorldChainMainnet Network = "worldchain-mainnet" WorldChainSepolia Network = "worldchain-sepolia" ZoraMainnet Network = "zora-mainnet" ZoraSepolia Network = "zora-sepolia" BerachainBartio Network = "berachain-bartio" FlowMainnet Network = "flow-mainnet" FlowTestnet Network = "flow-testnet" )
Other networks.
func AllNetworks ¶
func AllNetworks() []Network
AllNetworks returns a list of all supported networks.
func MainnetNetworks ¶
func MainnetNetworks() []Network
MainnetNetworks returns a list of all mainnet networks.
func (Network) ChainID ¶
ChainID returns the chain ID for the network. Returns 0 if the network is unknown.
func (Network) IsEthereum ¶
IsEthereum returns true if this is an Ethereum network.
func (Network) NativeCurrency ¶
NativeCurrency returns the native currency symbol for the network.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package client provides HTTP and JSON-RPC client implementations for the Alchemy SDK.
|
Package client provides HTTP and JSON-RPC client implementations for the Alchemy SDK. |
|
Package data provides the Data API client for Alchemy's enhanced APIs.
|
Package data provides the Data API client for Alchemy's enhanced APIs. |
|
Package errors provides error types for the Alchemy SDK.
|
Package errors provides error types for the Alchemy SDK. |
|
examples
|
|
|
basic
command
Package main demonstrates basic usage of the Alchemy SDK.
|
Package main demonstrates basic usage of the Alchemy SDK. |
|
nfts
command
Package main demonstrates querying NFTs using the Alchemy SDK.
|
Package main demonstrates querying NFTs using the Alchemy SDK. |
|
transfers
command
Package main demonstrates querying asset transfers using the Alchemy SDK.
|
Package main demonstrates querying asset transfers using the Alchemy SDK. |
|
internal
|
|
|
hex
Package hex provides utilities for encoding and decoding hexadecimal values commonly used in Ethereum JSON-RPC APIs.
|
Package hex provides utilities for encoding and decoding hexadecimal values commonly used in Ethereum JSON-RPC APIs. |
|
Package node provides the Node API client for JSON-RPC methods.
|
Package node provides the Node API client for JSON-RPC methods. |
|
Package types provides common types used across the Alchemy SDK.
|
Package types provides common types used across the Alchemy SDK. |
|
Package wallet provides high-level wallet operations using the Alchemy API.
|
Package wallet provides high-level wallet operations using the Alchemy API. |