connection.ts 723 B

123456789101112131415161718192021222324
  1. import { Connection, Keypair } from '@solana/web3.js'
  2. import bs58 from 'bs58'
  3. import { getEnvOrThrow } from '../utils'
  4. let connectionInstance: Connection | null = null
  5. export function getConnection(): Connection {
  6. if (!connectionInstance) {
  7. const endpoint =
  8. process.env.RPC_ENDPOINT || 'https://api.mainnet-beta.solana.com'
  9. connectionInstance = new Connection(endpoint, {
  10. commitment: 'confirmed',
  11. wsEndpoint:
  12. process.env.WS_ENDPOINT || 'wss://api.mainnet-beta.solana.com',
  13. })
  14. }
  15. return connectionInstance
  16. }
  17. export function getFollowerKeypair(): Keypair {
  18. const privateKey = getEnvOrThrow('FOLLOWER_PRIVATE_KEY')
  19. const secretKey = bs58.decode(privateKey)
  20. return Keypair.fromSecretKey(secretKey)
  21. }