Getting Started

This guide will help you quickly set up and send transactions on Solana using Helius. Follow these steps to send your first transaction with optimal settings.

Prerequisites

  • A Helius API key - Sign up here
  • Node.js installed on your machine
  • Basic knowledge of Solana transactions

Installation

Install the Helius SDK:

npm install helius-sdk @solana/web3.js bs58

Implementation

1

Initialize the Helius Client

import { Helius } from 'helius-sdk';
import { 
  Keypair, 
  SystemProgram, 
  LAMPORTS_PER_SOL,
  PublicKey 
} from '@solana/web3.js';

// Initialize Helius with your API key
const helius = new Helius('YOUR_API_KEY');
2

Create a Simple Transfer Transaction

// Create a new keypair (or load your existing one)
const payer = Keypair.generate();
// Recipient address
const recipientAddress = new PublicKey('RECIPIENT_ADDRESS');

// Create a transfer instruction
const transferInstruction = SystemProgram.transfer({
  fromPubkey: payer.publicKey,
  toPubkey: recipientAddress,
  lamports: 0.01 * LAMPORTS_PER_SOL // 0.01 SOL
});

// Array of instructions
const instructions = [transferInstruction];

// Array of signers
const signers = [payer];
3

Send the Transaction Using Smart Transactions

// Send options
const sendOptions = {
  skipPreflight: true, // Optional
  maxRetries: 0, // Recommended
};

try {
  // Send the transaction
  const txid = await helius.rpc.sendSmartTransaction(
    instructions,
    signers,
    [], // Optional lookup tables
    sendOptions
  );
  
  console.log(`Transaction sent! Signature: ${txid}`);
} catch (error) {
  console.error(`Error sending transaction: ${error}`);
}