Cryptography and the Solana Network

date
Jul 9, 2024
slug
cryptography-and-solana-network
status
Published
tags
Solana
summary
• A keypair is a matching pair of public key and secret key. • The public key is used as an “address” that points to an account on the Solana network. A public key can be shared with anyone. • The secret key is used to verify authority over the account. As the name suggests, you should always keep secret keys secret. • @solana/web3.js provides helper functions for creating a brand new keypair, or for constructing a keypair using an existing secret key.
type
Post
  1. Using @solana/web3.js to make a keypair
npm i @solana/web3.js
import { Keypair } from "@solana/web3.js"; const keypair = Keypair.generate(); console.log(`The public key is: `, keypair.publicKey.toBase58()); console.log(`The secret key is: `, keypair.secretKey);
  1. Lab
    1. Install
mkdir generate-keypair cd generate-keypair npm init -y npm install typescript @solana/web3.js esrun @solana-developers/helpers
 
import { Keypair } from "@solana/web3.js"; const keypair = Keypair.generate(); console.log(`✅ Generated keypair!`)
import "dotenv/config" import { getKeypairFromEnvironment } from "@solana-developers/helpers"; const keypair = getKeypairFromEnvironment("SECRET_KEY"); console.log( `✅ Finished! We've loaded our secret key securely, using an env file!` );