Alchemy Logo

Solana API Quickstart

How to get started building on Solana using Alchemy

Don't have an API key?

Build faster with production-ready APIs, smart wallets and rollup infrastructure across 70+ chains. Create your free Alchemy API key and get started today.

Let's use @solana/web3.js package to set up a Connection with Alchemy and get the latest slot on Solana!

npm install --save @solana/web3.js

import { Connection } from "@solana/web3.js";
 
const connection = new Connection(
  "https://solana-devnet.g.alchemy.com/v2/YOUR_ALCHEMY_API_KEY",
  "confirmed"
);
 
const slot = await connection.getSlot();
console.log("Current slot:", slot);

Now that you've set up a connection to Alchemy, you can continue with some basics:

import { Keypair } from "@solana/web3.js";
 
const wallet = Keypair.generate();
console.log("Public Key:", wallet.publicKey.toBase58());

const balance = await connection.getBalance(wallet.publicKey);
console.log("Balance:", balance / 1e9, "SOL");

const info = await connection.getAccountInfo(wallet.publicKey);
console.log(info);

Want to estimate your Solana Compute Units (CUs) before running transactions?
Try the CU Calculator now: Open CU Calculator →

You must not stop here! Check out the following tutorials to learn how to build with Solana:

Was this page helpful?