{"id":22173813,"url":"https://github.com/puneethkumarck/solana-web3-bootcamp","last_synced_at":"2025-03-24T17:47:13.134Z","repository":{"id":255494965,"uuid":"851322377","full_name":"Puneethkumarck/solana-web3-bootcamp","owner":"Puneethkumarck","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-05T19:21:44.000Z","size":19542,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T22:33:36.746Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Puneethkumarck.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-02T21:57:13.000Z","updated_at":"2024-09-05T19:21:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b3e1f94-0e46-4b3a-967f-4929abf48443","html_url":"https://github.com/Puneethkumarck/solana-web3-bootcamp","commit_stats":null,"previous_names":["puneethkumarck/solana-web3-bootcamp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fsolana-web3-bootcamp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fsolana-web3-bootcamp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fsolana-web3-bootcamp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Puneethkumarck%2Fsolana-web3-bootcamp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Puneethkumarck","download_url":"https://codeload.github.com/Puneethkumarck/solana-web3-bootcamp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245321022,"owners_count":20596288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T07:35:40.257Z","updated_at":"2025-03-24T17:47:13.114Z","avatar_url":"https://github.com/Puneethkumarck.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Solana Transaction Script\n\nThis project provides a Node.js script to facilitate sending SOL (Solana's cryptocurrency) from one account to another on the Solana blockchain using the Solana Web3.js SDK. The script handles connecting to the Solana network, loading keypairs from environment variables, validating public keys, and checking balances before sending the transaction.\n\n## Features\n\n- **Connect to Solana Network**: Supports devnet, testnet, and mainnet-beta clusters.\n- **Load Keypairs**: Loads the sender's keypair from an environment variable for security.\n- **Balance Check**: Checks the balances of both sender and recipient accounts before initiating a transaction.\n- **Airdrop Request**: Requests airdrops to top up balances for testing on the devnet.\n- **Transaction Creation**: Constructs and sends a transaction to transfer SOL between accounts.\n\n## Prerequisites\n\nBefore running the script, ensure that you have the following:\n\n- Node.js installed on your machine.\n\n- A Solana CLI installed and set up.\n- A `.env` file with the sender's `SECRET_KEY` in base64 or JSON format (steps to generate a keypair below).\n- Solana Web3.js SDK installed (`@solana/web3.js`).\n- An internet connection to connect to the Solana network.\n\n### 1. Generate a Keypair\n\nTo create a new keypair for your Solana account, use the `solana-keygen` command:\n\n```bash\nsolana config get\nsolana config set --url https://api.devnet.solana.com\nsolana-keygen new --outfile ~/my-keypair.json\n```\n\n![alt text](doc/image.png)\n\nThis will generate a new keypair and store it in `my-keypair.json`. You can find the public key by running:\n\n```bash\nsolana-keygen pubkey ~/my-keypair.json\n```\n\n### 2. Fund Your Account\n\nYou can use the Solana Devnet to get test funds for your account. Use the `solana airdrop` command to send 1 SOL to your account:\n\n```bash\nsolana airdrop 1 \u003cyour-public-key\u003e --url https://api.devnet.solana.com\n```\n\nIf you need more funds, you can request additional airdrops.\n\n## Installation\n\n1. Clone this repository:\n\n```bash\ngit clone https://github.com/Puneethkumarck/solana-web3-bootcamp.git\n```\n\n2. Install dependencies:\n\n```bash\n   cd solana-web3-bootcamp\n   npm install\n```\n\n3. Create a `.env` file in the root of your project and add the `SECRET_KEY` environment variable:\n\n```bash\n   SECRET_KEY=\u003cyour_base64_or_json_secret_key\u003e\n```\n\n## Usage\n\nTo execute the script, you need to provide the recipient's public key as a command-line argument.\n\n### Example:\n\n```bash\nnpx tsc transfer.ts \u003crecipient-public-key\u003e\n```\n\nFor example:\n\n```bash\nnpx tsc transfer.ts GFC68tMFVSEodZVsCoW1Do4tAeL9j7WVVggtQXBJqSE2\n```\n\n![alt text](doc/logs.png)\n![alt text](doc/dev_explorer.png)\n\n## Key Functions\n\n- **`createConnection(cluster)`**: Connects to the Solana network.\n- **`loadSenderKeypair()`**: Loads the sender's keypair from the environment variable.\n- **`isValidPublicKey(pubkey)`**: Validates if the supplied string is a valid Solana public key.\n- **`getAccountBalance(connection, publicKey)`**: Retrieves the balance of the specified account.\n- **`createTransaction(fromPubkey, toPubkey, lamports)`**: Creates a transaction to transfer SOL.\n- **`main()`**: Main function that runs the script and handles the entire transaction process.\n\n## Error Handling\n\nThe script checks for common issues such as:\n\n- Invalid public keys.\n- Insufficient funds for rent exemption or transactions.\n- Failed network or transaction issues.\n\n## Airdrop Feature\n\nOn the Solana devnet, the script requests an airdrop for both the sender and recipient if their balances are too low to perform the transaction or to meet rent exemption requirements.\n\n## Logging\n\nThe script logs key steps, such as:\n\n- Loading of keypair.\n- Connection to the network.\n- Balance checks.\n- Transaction progress and any errors encountered.\n\n\n## References\n[Solana Devnet Explorer](https://explorer.solana.com/?cluster=devnet)  \n[Solana Devnet Faucet](https://faucet.solana.com/)  \n[Solana Development Guides](https://www.quicknode.com/guides/tags/solana)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fsolana-web3-bootcamp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpuneethkumarck%2Fsolana-web3-bootcamp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpuneethkumarck%2Fsolana-web3-bootcamp/lists"}