Skip to content

rathe-tech/solana-signers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana Signers

Version License Downloads Downloads

Transaction signer implementation for Ledger devices and the standard Solana Keypair class. Both legacy and versioned transactions are supported.

Install with npm:

npm install --save @rathe/solana-signers

Usage

import {
  Connection,
  Keypair,
  SystemProgram,
  LAMPORTS_PER_SOL,
  Transaction
} from "@solana/web3.js";
import { LedgerTransactionSigner, NaclTransactionSigner } from "@rathe/solana-signers";

const connection = new Connection("http://127.0.0.1:8899", "confirmed");

const bip32Path = "LEDGER_BIP32_PATH";
const ledgerSigner = await LedgerTransactionSigner.create(bip32Path);

const keypair = Keypair.generate();
const naclSigner = new NaclTransactionSigner(keypair);

const isLedger = true;
const signer = isLedger ? ledgerSigner : naclSigner;
const fromAddress = signer.publicKey;
const toKeypair = Keypair.generate();
const lamportsToSend = 1_000_000;

const transferTransaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: fromAddress,
    toPubkey: toKeypair.publicKey,
    lamports: lamportsToSend
  })
);

await signer.signTransaction(transferTransaction);
const signature = await connection.sendRawTransaction(transferTransaction.serialize());

const result = await connection.confirmTransaction(signature);
if (result.value.err != null) {
  throw result.value.err;
} else {
  console.log("Transaction confirmed: %o", signature);
}

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published