Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2022 01:53
What would you like to do?
Solana 101: Creating Solana Accounts AKA Keypair (From's Solana 101 Course)
import type {NextApiRequest, NextApiResponse} from 'next';
import {Keypair} from '@solana/web3.js';
* Like with most Web 3 protocols, transactions on Solana happen between accounts.
* To create an account, a client generates a keypair which has a public key (or
* address, used to identify and lookup an account) and a secret key used to sign
* transactions.
type ResponseT = {
secret: string;
address: string;
export default function keypair(
_req: NextApiRequest,
res: NextApiResponse<string | ResponseT>,
) {
try {
const keypair = Keypair.generate();
const address = keypair?.publicKey.toString();
const secret = JSON.stringify(Array.from(keypair.secretKey));
} catch (error) {
let errorMessage = error instanceof Error ? error.message : 'Unknown Error';
Copy link

Sol... Donasi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment