A Complete Guide to Wrapping, Transferring, and Unwrapping SOL on Solana

·

This guide provides a detailed walkthrough of interacting with Wrapped SOL (wSOL) on the Solana blockchain using Solana Web3.js, Solana CLI, and Solana Rust SDK. Learn how to wrap, transfer, and unwrap SOL with step-by-step instructions and code examples tailored for developers.

Overview

Wrapped SOL (wSOL) is an SPL token representing native SOL on the Solana blockchain. This guide covers:

👉 Master Solana development with these expert tips

Prerequisites

Dependencies

| Dependency | Version |
|-------------------------|--------------|
| @solana/web3.js | ^1.91.1 |
| @solana/spl-token | ^0.3.9 |
| Solana CLI | 1.18.8 |


What Is Wrapped SOL?

Wrapped SOL (wSOL) is an SPL token that represents native SOL, enabling compatibility with DeFi protocols like decentralized exchanges (DEXs). Key features:

👉 Explore advanced Solana token strategies


Solana Web3.js Method

Step 1: Wrap SOL

import { Connection, Keypair, LAMPORTS_PER_SOL, Transaction } from "@solana/web3.js";
import { NATIVE_MINT, createSyncNativeInstruction } from "@solana/spl-token";

async function wrapSol(connection: Connection, wallet: Keypair) {
  const associatedTokenAccount = await getAssociatedTokenAddress(
    NATIVE_MINT,
    wallet.publicKey
  );
  const tx = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: wallet.publicKey,
      toPubkey: associatedTokenAccount,
      lamports: LAMPORTS_PER_SOL,
    }),
    createSyncNativeInstruction(associatedTokenAccount)
  );
  await sendAndConfirmTransaction(connection, tx, [wallet]);
}

Step 2: Transfer wSOL

async function transferWrappedSol(connection: Connection, sender: Keypair, recipient: Keypair, tokenAccount: PublicKey) {
  const recipientAccount = await getAssociatedTokenAddress(NATIVE_MINT, recipient.publicKey);
  const tx = new Transaction().add(
    createTransferInstruction(tokenAccount, recipientAccount, sender.publicKey, LAMPORTS_PER_SOL / 2)
  );
  await sendAndConfirmTransaction(connection, tx, [sender]);
}

Step 3: Unwrap SOL

async function unwrapSol(connection: Connection, wallet: Keypair, tokenAccount: PublicKey) {
  const tx = new Transaction().add(
    createCloseAccountInstruction(tokenAccount, wallet.publicKey, wallet.publicKey)
  );
  await sendAndConfirmTransaction(connection, tx, [wallet]);
}

Solana CLI Method

1. Wrap SOL

spl-token wrap 1 wallet1.json

2. Transfer wSOL

spl-token transfer So11111111111111111111111111111111111111112 0.5 <RECIPIENT_ADDRESS> --owner wallet1.json

3. Unwrap SOL

spl-token unwrap --owner wallet1.json

Solana Rust SDK

Rust Implementation

use solana_client::rpc_client::RpcClient;
use spl_token::{native_mint, instruction::sync_native};

fn wrap_sol(client: &RpcClient, wallet: &Keypair) -> Result<(), Box<dyn std::error::Error>> {
    let ata = get_associated_token_address(&wallet.pubkey(), &native_mint::id());
    let tx = Transaction::new_signed_with_payer(
        &[
            system_instruction::transfer(&wallet.pubkey(), &ata, 1_000_000_000),
            sync_native(&spl_token::id(), &ata)?,
        ],
        Some(&wallet.pubkey()),
        &[wallet],
        client.get_latest_blockhash()?,
    );
    client.send_and_confirm_transaction(&tx)?;
    Ok(())
}

FAQs

1. Why wrap SOL?

Wrapping SOL allows interoperability with SPL-based applications like DEXs and lending protocols.

2. Is wSOL safe?

Yes, wSOL is a 1:1 representation of SOL audited by Solana’s core team.

3. Can I unwrap wSOL anytime?

Yes, unwrapping returns native SOL instantly.

👉 Start building on Solana today


Conclusion

This guide covered:

For more advanced usage, refer to the Solana documentation.

Happy coding! 🚀


### Key Improvements:  
1. **SEO Optimization**: Integrated keywords like "Solana," "Wrapped SOL," "SPL tokens," and "DeFi."  
2. **Structure**: Used hierarchical Markdown headings for better readability.  
3. **Engagement**: Added anchor texts and FAQs to boost user interaction.