Sending transactions is one of the most fundamental operations in blockchain development. Whether you're building decentralized applications, wallets, or token transfer tools, understanding how to programmatically send a transaction on Solana is essential. In this step-by-step guide, you’ll learn how to send a Solana transaction using solana-web3.js—one of the most widely used SDKs for Solana development.
By the end of this tutorial, you’ll be able to set up a Node.js environment, connect to the Solana network, and push a live transaction—all within minutes.
Install solana-web3.js and Base58 Libraries
To get started, ensure you have Node.js installed on your machine. Then, initialize a new project and install the required dependencies.
First, install the official Solana web3 library:
npm install @solana/web3.jsThis library provides all the necessary tools to interact with the Solana blockchain, including creating accounts, signing transactions, and connecting to nodes.
Next, install the bs58 library to handle Base58-encoded private keys—commonly used by wallets like Phantom:
npm install bs58👉 Discover how easy it is to build powerful blockchain interactions today.
Set Up Your Project Environment
After installing the dependencies, create an index.js file and import the required modules:
const web3 = require("@solana/web3.js");
const bs58 = require("bs58");These imports give you access to Solana’s core functionality and Base58 decoding for private key handling.
Connect to the Solana Network
To interact with the blockchain, you need a connection to a Solana node. While public endpoints exist, using a dedicated node ensures reliability and performance.
You can deploy a free Solana node via infrastructure platforms that offer managed blockchain services. Once deployed, copy the HTTPS endpoint provided in the dashboard.
Use this endpoint to establish a connection:
const connection = new web3.Connection("YOUR_HTTPS_ENDPOINT_HERE");This connection object will be used to send and confirm transactions on the network.
Load Your Private Key and Derive Account
Security is critical when handling private keys. Never hardcode sensitive data in your source files—use environment variables instead.
Assuming your private key is stored in a .env file as a Base58-encoded string:
const privateKey = new Uint8Array(bs58.decode(process.env.PRIVATE_KEY));Now, derive the keypair from the decoded private key:
const account = web3.Keypair.fromSecretKey(privateKey);This account represents the sender of the transaction and includes both public and private key components.
Generate a Recipient Account
For demonstration purposes, generate a new random account to receive SOL:
const recipient = web3.Keypair.generate();In real-world applications, you’d typically use a known public address (e.g., from user input or wallet connection). Here, we're simulating a transfer to a newly created wallet.
Create and Send the Transaction
Now, construct a transaction that transfers a small amount of SOL (measured in lamports):
(async () => {
const transaction = new web3.Transaction().add(
web3.SystemProgram.transfer({
fromPubKey: account.publicKey,
toPubKey: recipient.publicKey,
lamports: web3.LAMPORTS_PER_SOL * 0.001, // 0.001 SOL
})
);
try {
const signature = await web3.sendAndConfirmTransaction(
connection,
transaction,
[account]
);
console.log("Transaction successful!");
console.log(`Signature: ${signature}`);
console.log(`Recipient Address: ${recipient.publicKey.toBase58()}`);
} catch (err) {
console.error("Transaction failed:", err);
}
})();This block:
- Creates a transfer instruction via the System Program.
- Sends and confirms the transaction.
- Outputs the transaction signature and recipient address.
👉 Learn how top developers streamline blockchain integration with efficient tools.
Core Concepts Recap
Here’s what you’ve accomplished:
- Installed
solana-web3.jsandbs58for blockchain interaction and key decoding. - Connected to the Solana network using a secure HTTPS endpoint.
- Loaded and decoded a private key to authenticate the sender.
- Generated a recipient account for testing.
- Built and executed a signed transaction on-chain.
You can verify the transaction on any Solana explorer by pasting the signature.
Frequently Asked Questions
How do I get a private key in Base58 format?
Wallets like Phantom export private keys in Base58 format when you choose to reveal them. Always store these securely and never expose them in client-side code or public repositories.
What are lamports in Solana?
Lamports are the smallest unit of SOL, similar to satoshis in Bitcoin. One SOL equals 1 billion lamports (web3.LAMPORTS_PER_SOL).
Can I send tokens other than SOL?
Yes! To send SPL tokens (Solana’s equivalent of ERC-20), you’ll need to use the @solana/spl-token library and interact with the Token Program instead of the System Program.
Do I need my own node to send transactions?
No, but it's recommended for production apps. Public RPCs work for testing, but they may be rate-limited or unreliable under heavy load.
How much does it cost to send a transaction?
Transaction fees on Solana are extremely low—typically less than $0.001. Fees are paid in SOL and vary slightly based on network congestion.
Is it safe to use environment variables for private keys?
Yes, as long as you use .env files that are excluded from version control (via .gitignore). For added security in production, consider using secret management services.
Optimize Your Development Workflow
Building on Solana requires reliable infrastructure. Using high-performance nodes ensures fast transaction finality and consistent API responses—critical for dApps handling real-time operations.
Whether you're working with mainnet or testnet environments, choosing the right backend support accelerates development and improves user experience.
👉 See how seamless blockchain development can be with optimized connectivity solutions.
Final Thoughts
Sending a transaction using solana-web3.js is straightforward once you understand the core components: connection setup, account management, and transaction construction. With just a few lines of code, you’ve executed a real blockchain operation.
As you continue exploring Solana development, consider diving into more advanced topics like interacting with smart contracts (programs), querying account states, or building frontends with React and WalletAdapter.
The ecosystem is growing rapidly, and mastering these foundational skills positions you at the forefront of Web3 innovation.
Core Keywords: Solana transaction, solana-web3.js, send SOL, Base58 private key, Solana blockchain, Node.js Solana, Lamports, SPL tokens