Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2022 01:48
What would you like to do?
Solana 101: Connect to Solana (From's Solana 101 Course)
import type {NextApiRequest, NextApiResponse} from 'next';
import {getNodeURL} from '@figment-solana/lib';
import {Connection} from '@solana/web3.js';
export default async function connect(
req: NextApiRequest,
res: NextApiResponse<string>,
) {
try {
const {network} = req.body;
const url = getNodeURL(network);
const connection = new Connection(url, 'confirmed');
const version = await connection.getVersion();
} catch (error) {
let errorMessage = error instanceof Error ? error.message : 'Unknown Error';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment