Skip to content

scopenco/Solana-transfer-demo

Repository files navigation

Solana Transfer Demo

This project is a Demo for sending SOL tokens on the Solana blockchain. It consists of:

  • A Rust smart contract (Anchor) deployed to Solana devnet.
  • A React frontend that allows users to send SOL using their Phantom Wallet.

The frontend connects to the smart contract and enables users to transfer SOL to any address on devnet.

Architecture

  • The Rust smart contract (programs/sender) exposes a send_sol instruction.
  • The frontend React app (app/) connects to the user's Phantom Wallet and calls the smart contract using Anchor's JS bindings.
  • Users input a recipient address and amount, and the transaction is sent via the smart contract.

Quick Start

  1. Install Solana CLI and Anchor:
    curl --proto '=https' --tlsv1.2 -sSfL https://solana-install.solana.workers.dev | bash
    npm install -g @coral-xyz/anchor-cli
  2. Create and fund a wallet on devnet:
    solana-keygen new
    solana config set --url devnet
    solana airdrop 2
    solana balance
  3. Sync wallet with Anchor project:
    anchor keys sync
  4. Build and deploy the Rust program:
    anchor build
    anchor deploy
  5. Copy the generated IDL to the frontend:
    cp target/idl/sol_transfer.json app/src/
  6. Install frontend dependencies and run the app:
    cd app
    npm install
    npm run dev
  7. Connect Phantom Wallet and send SOL:
    • Open the app in your browser.
    • Connect your Phantom Wallet (ensure it's set to Devnet).
    • Enter a recipient address and amount, then click Send.
    • View the transaction on Solscan via the provided link.

Troubleshooting

  • Transaction fails:
    • Ensure you have enough SOL in your wallet.
    • Make sure Phantom is set to Devnet.
    • Check the recipient address is valid.
  • Check transaction status:
    • Use the Solscan link provided after sending.

Future Improvements

  • Add support for SPL tokens.
  • Improve error handling and UI feedback.
  • Add more comprehensive tests for the smart contract.
  • Provide deployment scripts for easier setup.

About

Demo for sending SOL with Anchor + Phantom in Devnet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published