Getting started overview
Getting started with Alchemy Ethereum involves a sequence of steps designed to provide access to blockchain data and functionality. This guide outlines the process from account creation to making your initial API call. Alchemy's infrastructure, including the Supernode, supports various Ethereum network interactions, from reading blockchain state to submitting transactions.
The primary method for interacting with Alchemy's services is through its JSON-RPC API. This API enables developers to send requests to the Ethereum network via Alchemy's nodes, abstracting away the complexities of running and maintaining a personal node. Alchemy also offers enhanced APIs, such as the NFT API, which simplify querying NFT-related data.
A typical workflow includes:
- Account Creation: Registering for an Alchemy account.
- Application Setup: Creating a new application within the Alchemy dashboard to generate API keys.
- Environment Configuration: Setting up your development environment and installing necessary client libraries.
- First Request: Executing a basic API call to verify connectivity and retrieve data.
Alchemy provides SDKs for JavaScript, Python, Go, and TypeScript to streamline interaction with its APIs.
Create an account and get keys
Accessing Alchemy's Ethereum infrastructure begins with creating an account and generating API keys. These keys are essential for authenticating your requests and connecting to the network.
Step 1: Sign up for an Alchemy account
Navigate to the Alchemy homepage and select the option to sign up. You will typically be prompted to provide an email address and create a password. Alchemy offers a Growth (free) tier that includes up to 50 million compute units per month, suitable for initial development and testing.
Step 2: Create a new application
After successfully signing up and logging into the Alchemy dashboard, you will need to create a new application. This application serves as a container for your API keys and configuration settings. Follow these steps:
- From the dashboard, locate and click the "Create App" or "New App" button.
- Name your application: Choose a descriptive name for your project.
- Select a chain: For Ethereum development, select "Ethereum".
- Select a network: Choose the desired network (e.g., "Mainnet" for the primary Ethereum network, or "Sepolia" for a testnet).
- Click "Create app" to finalize the setup.
Step 3: Retrieve your API key
Upon creating an application, Alchemy automatically generates unique API keys for it. To access these keys:
- In your Alchemy dashboard, navigate to the "Apps" section.
- Select the application you just created.
- The application details page will display your "API Key" and "API URL" for various networks.
- Copy the HTTPS or WebSocket URL for the network you intend to use. This URL includes your API key and is used to make requests to Alchemy.
Quick Reference: Account and Key Setup
| Step | What to Do | Where |
|---|---|---|
| 1. Sign Up | Register for an Alchemy account. | Alchemy Homepage |
| 2. Create App | Create a new application in the dashboard. | Alchemy Dashboard > "Create App" |
| 3. Get API Key | Copy the API URL (HTTPS/WSS) for your app. | Alchemy Dashboard > Your App > "View Key" |
Your first request
With your API key in hand, you can now make your first request to the Ethereum network via Alchemy. This example demonstrates fetching the latest block number using the eth_blockNumber JSON-RPC method.
Using curl (Command Line)
A basic curl request can verify your API key and connectivity. Replace YOUR_ALCHEMY_HTTPS_URL with the HTTPS API URL you copied from your Alchemy dashboard (e.g., https://eth-mainnet.alchemyapi.io/v2/YOUR_API_KEY).
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
"YOUR_ALCHEMY_HTTPS_URL"
A successful response will look similar to this, with the result field containing the block number in hexadecimal format:
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x12b4f80"
}
Using JavaScript (with ethers.js or web3.js)
For JavaScript development, popular libraries like ethers.js or web3.js simplify interacting with Ethereum. First, install the library:
npm install ethers
Then, use the following code snippet. Replace YOUR_ALCHEMY_HTTPS_URL with your actual API URL.
const { ethers } = require("ethers");
async function getBlockNumber() {
const provider = new ethers.JsonRpcProvider("YOUR_ALCHEMY_HTTPS_URL");
try {
const blockNumber = await provider.getBlockNumber();
console.log("Latest block number:", blockNumber);
} catch (error) {
console.error("Error fetching block number:", error);
}
}
getBlockNumber();
The output in your console should display the latest block number:
Latest block number: 12345678
Using Python (with web3.py)
For Python development, the web3.py library is commonly used. Install it first:
pip install web3
Then, use this Python script. Replace YOUR_ALCHEMY_HTTPS_URL with your actual API URL.
from web3 import Web3
def get_block_number():
w3 = Web3(Web3.HTTPProvider("YOUR_ALCHEMY_HTTPS_URL"))
if w3.is_connected():
block_number = w3.eth.block_number
print(f"Latest block number: {block_number}")
else:
print("Failed to connect to Ethereum node.")
if __name__ == "__main__":
get_block_number()
The console output will show the latest block number:
Latest block number: 12345678
These examples demonstrate a fundamental interaction. Alchemy's API reference provides details on other available JSON-RPC methods, such as eth_getBalance for checking account balances or eth_getTransactionReceipt for transaction details.
Common next steps
After successfully making your first request, several common next steps can further your development with Alchemy Ethereum:
- Explore Enhanced APIs: Alchemy offers specialized APIs, such as the NFT API for querying NFT data and the Transfers API for tracking token movements. These APIs abstract complex blockchain interactions into simpler requests.
- Set up Webhooks with Alchemy Notify: For real-time updates on blockchain events (e.g., new blocks, pending transactions, token transfers), configure Alchemy Notify webhooks. This push-based system can reduce polling and improve application responsiveness.
- Utilize Developer Tools: Explore tools like the Transaction Simulator for testing transaction outcomes before deployment or the Mempool Visualizer to observe pending transactions.
- Integrate with a Frontend: If building a decentralized application (dApp), integrate your Alchemy backend with a frontend framework (e.g., React, Vue, Angular) using libraries like
ethers.jsorweb3.js. For guidance on frontend development patterns, resources like MDN Web Docs on Asynchronous JavaScript can be helpful. - Monitor Usage: Regularly check your application's usage metrics in the Alchemy dashboard. This helps manage compute unit consumption and avoid hitting free tier limits or incurring unexpected costs on paid plans.
- Explore Testnets: Develop and test your dApps on Ethereum testnets like Sepolia before deploying to the Mainnet. Alchemy supports various Ethereum testnets, which provide a safe environment for experimentation without using real assets.
Troubleshooting the first call
If your first API call to Alchemy fails, consider these common troubleshooting steps:
- Verify API Key and URL: Double-check that the HTTPS API URL copied from your Alchemy dashboard is correct and contains your valid API key. Even a single character mismatch can cause authentication errors.
- Check Network Selection: Ensure that the network specified in your API URL (e.g., Mainnet, Sepolia) matches the network configuration of your Alchemy application. An API key for Sepolia will not work on Mainnet.
- Review Request Body: For JSON-RPC requests, confirm that the JSON payload is correctly formatted. Pay attention to quotation marks, commas, and curly braces. The
jsonrpcversion,method,paramsarray, andidfields are all critical. - Firewall or Proxy Issues: If you are working within a corporate network, a firewall or proxy might be blocking outbound requests to Alchemy's endpoints. Consult your network administrator if you suspect this is the case.
- Internet Connectivity: Ensure your development environment has a stable internet connection.
- Alchemy Status Page: Check the Alchemy status page for any ongoing service disruptions or outages that might affect connectivity or API responsiveness.
- Consult Alchemy Documentation: The Alchemy Getting Started guide often contains detailed troubleshooting sections and FAQs.
- Error Messages: Carefully read any error messages returned in the API response. These messages often provide specific clues about what went wrong (e.g., "Invalid API key", "Method not found").