Created
January 14, 2022 01:48
-
-
Save topherPedersen/d912f61088c86c082453a72419eb3ca3 to your computer and use it in GitHub Desktop.
Solana 101: Connect to Solana (From Figment.io's Solana 101 Course)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
res.status(200).json(version['solana-core']); | |
} catch (error) { | |
let errorMessage = error instanceof Error ? error.message : 'Unknown Error'; | |
res.status(500).json(errorMessage); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment