Send a Solana Transaction Javascript-SDK

Hi All,

I am working on my first Solana transaction. I am struggling through a few issues. Here is the code I am working with.

const solanaWeb3 = require('@solana/web3.js');

const {Keypair, Transaction, SystemProgram, LAMPORTS_PER_SOL} = require("@solana/web3.js");

let transaction = new Transaction();

    fromPubkey: fromKeypair.publicKey,
    toPubkey: toKeypair.publicKey,
    lamports: LAMPORTS_PER_SOL

I am running my code from the command line. On issues, first, how do I connect this script to Solana Test Network? Second, how do I define the toPubkey and fromPubkey variables? Third, what are the fundemental essential elements for sending a transaction from Alice to Bob with the JavaScript-SDK? Fourth, what are lamports?

Any advice or suggestions would be greatly appreciated, thank you!

This post was flagged by the community and is temporarily hidden.


const web3 =  require("@solana/web3.js");

(async () => {
  // Connect to cluster
  const connection = new web3.Connection(
  // Uncomment the below command to test your connection to your node
  //console.log(await connection.getEpochInfo())

  // Using the secretkey to generate the keypair
  const secretkey = Uint8Array.from(['']);  

  //If you already have enough test sol in your account you can comment this out
  const airdropSignature = await connection.requestAirdrop(
  await connection.confirmTransaction(airdropSignature);

  // Add transfer instruction to transaction
  const transaction = new web3.Transaction().add(
      fromPubkey: from.publicKey,
      toPubkey: '',
      lamports: web3.LAMPORTS_PER_SOL / 100,

  // Sign transaction, broadcast, and confirm
  const signature = await web3.sendAndConfirmTransaction(
  console.log('SIGNATURE', signature);

// SIGNATURE 36bvGs1ddyfYJeGudoDKm4fFW7HgULWKRz7vGgWjv3g33NsvQMgKyu9Mb9eGc8VuetVd2BVTyUVt7TeVU8j5dJ6V

Still facing challenges finding ways to generate the secret key from the passphrase, but with a secret key inserted, this code works.