Solana Client: Transfer SOL
This repository contains a simple Solana client that transfers SOL tokens between two accounts on the Solana devnet. It is built using the Solana JavaScript API and is designed for educational purposes. This Solana client was built as part of the 6-week Solana Core Developer Program on buildspace.
Solana Explorer - Result of Token Transfer
Table of Contents
- Features
- Getting Started
- Prerequisites
- Installation
- Usage
- Understanding the Code
- Resources
- Contributing
- License
- Support
Features
- Connect to a Solana cluster (Devnet in this case)
- Generate a new keypair if not provided
- Airdrop SOL tokens to the account if the balance is less than 1 SOL
- Transfer SOL tokens to another account
Getting Started
Follow these steps to set up the project locally.
Prerequisites
Before getting started, make sure you have the following software installed on your system:
- Node.js (version 14.x or later)
This project was built using Node.js v18.14.0. If you use NVM, you can run nvm use
to switch to this version.
Installation
- Fork and then clone this repository:
git clone https://github.com/<your username>/solana-client_transfer-SOL.git
- Change to the project directory:
cd solana-client_transfer-SOL
- Install the dependencies:
npm ci
Usage
- Start the script:
npm start
- The script will generate a new keypair if not provided and airdrop 1 SOL token to the account if the balance is less than 1 SOL.
- The script will transfer 0.1 SOL to a randomly generated account and display the transaction link.
Understanding the Code
- The
initializeKeypair()
function generates a new keypair if not provided and requests an airdrop if the account balance is less than 1 SOL. - The
transferSol()
function transfers the specified amount of SOL tokens to the given account. - The
main()
function initializes the connection to Solana devnet, sets up the keypair, and transfers 0.1 SOL to a randomly generated account.
Resources
- Solana Web3.js Documentation
- Solana Developer Guide
- Solana Explorer
- Solana Core Developer Program at buildspace
Contributing
Contributions are always welcome! If you'd like to contribute to this project or have any suggestions, feel free to create a new issue or submit a pull request. Please check the Code of Conduct first.
To submit a pull request, follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/your-feature-name
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin feature/your-feature-name
) - Create a new Pull Request
License
This project is open-source and available under the MIT License.
Support
If you have any questions or need help getting started, please open an issue in the repository or contact me on Twitter: @tanja_codes