πŸš€ Getting Started With Alchemy

Quick start guide to Alchemy: fast, reliable, and scalable tools built for blockchain developers.

β€‹πŸ‘‹ New to Alchemy? Get access to Alchemy for free here.

β€‹πŸ“‹ Steps to get started with Alchemy

This guide assumes you already have an Alchemy account and access to our Dashboard.

1. πŸ”‘ Create an Alchemy key

2. ✍ Make a request

3. 🀝 Set up Alchemy as your client

1.πŸ”‘Create an Alchemy Key

To use Alchemy's products, you need an API key to authenticate your requests.

You can create API keys from the dashboard. To make a new key, navigate to "Create App" as shown below:

Fill in the details under "Create App" to get your new key. You can also see apps you previously made and those made by your team here. Pull existing keys by clicking on "View Key" for any app.

You can also pull existing API keys by hovering over "Apps" and selecting one. You can "View Key" here, as well as "Edit App" to whitelist specific domains, see several developer tools, and view analytics.

2.✍Make a Request

Interact with Alchemy's Ethereum infrastructure provider using JSON-RPC and curl.

For manual requests, we recommend interacting with the JSON-RPC via POST requests. Simply pass in the Content-Type: application/json header and your query as the POST body with the following fields:

  • jsonrpc: The JSON-RPC versionβ€”currently, only 2.0 is supported.

  • method: The ETH API method. See API reference.​

  • params: A list of parameters to pass to the method.

  • id: The ID of your request. Will be returned by the response so you can keep track of which request a response belongs to.

Here is an example you can run from the command line to retrieve the current gas price:

curl https://eth-mainnet.alchemyapi.io/v2/demo \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":73}'

Results:

{ "id": 73,
"jsonrpc": "2.0",
"result": "0x09184e72a000" // 10000000000000 }

3.🀝Set up Alchemy as your Client

Below you will find how to set up or switch your current provider to Alchemy for Web3.js, Web3.py, Web3j, Ether.js, and Alchemy Web3.

You may use other instantiations of the Web3 client and use the Alchemy URL of your choosing with a one-line configuration change. You will need to install web3 first with npm install web3.

Note: These scripts need to be run in a node context or saved in a file, not run from the command line.

If you have an existing client, change your current node provider URL to an Alchemy URL with your API key: "https://eth-mainnet.alchemyapi.io/v2/your-api-key"

Web3.js

See the official documentation for quick start guides and more information.

// JavaScript: web3.js
const Web3 = require('web3');
const web3 = new Web3("https://eth-mainnet.alchemyapi.io/v2/your-api-key");

Web3.py

See the official documentation for quick start guides and more information.

# Python: web3.py
web3 = Web3(Web3.HTTPProvider("https://eth-mainnet.alchemyapi.io/v2/your-api-key"));

Web3j

See the official documentation for quick start guides and more information.

// Java: web3j
Web3j web3 = Web3j.build(new HttpService("https://eth-mainnet.alchemyapi.io/v2/your-api-key"));

Ether.js

See the official documentation for quick start guides and more information.

// Ethers.js
const url = "https://eth-mainnet.alchemyapi.io/v2/your-api-key";
const customHttpProvider = new ethers.providers.JsonRpcProvider(url);

Alchemy Web3

We recommend using AlchemyWeb3.js for an enhanced Web3 JavaScript library, which we built as an extended version of web3.js that also includes Alchemy enhanced API. For more information, please refer to the Alchemy Web3 guide.

Before you install, make sure you are in the desired directory as AlchemyWeb3.js will install in the current directory.

To install AlchemyWeb3.js, run in the command line:

With Yarn:

yarn add @alch/alchemy-web3

With NPM:

npm install @alch/alchemy-web3

To interact with Alchemy's node infrastructure, run in NodeJS or other JavaScript environment:

import { createAlchemyWeb3 } from "@alch/alchemy-web3";
const web3 = createAlchemyWeb3("https://eth-mainnet.alchemyapi.io/v2/demo",);

For a more detailed explanation of import functions in JavaScript, read this!