{"id":24072506,"url":"https://github.com/jongan69/lotteryprogram","last_synced_at":"2025-02-26T22:14:08.765Z","repository":{"id":269082911,"uuid":"906320605","full_name":"jongan69/lotteryprogram","owner":"jongan69","description":"A solana program for creating and participating in decentralized lotteries using switchboard vrf","archived":false,"fork":false,"pushed_at":"2025-01-05T05:27:16.000Z","size":1509,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-05T06:24:54.628Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://lotto.cooking/","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/jongan69.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-12-20T16:27:31.000Z","updated_at":"2025-01-05T05:27:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"3cb57119-2317-4c61-9197-1b13169f2fc2","html_url":"https://github.com/jongan69/lotteryprogram","commit_stats":null,"previous_names":["jongan69/lotteryprogram"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongan69%2Flotteryprogram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongan69%2Flotteryprogram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongan69%2Flotteryprogram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jongan69%2Flotteryprogram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jongan69","download_url":"https://codeload.github.com/jongan69/lotteryprogram/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240941541,"owners_count":19882063,"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":"2025-01-09T17:17:52.634Z","updated_at":"2025-02-26T22:14:08.745Z","avatar_url":"https://github.com/jongan69.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n![Switchboard Logo](https://github.com/switchboard-xyz/core-sdk/raw/main/website/static/img/icons/switchboard/avatar.png)\n\n# Switchboard On-Demand: Lottery Example\nThis example demonstrates how to build a decentralized lottery using Switchboard's On-Demand Randomness functionality.\n\n\u003c/div\u003e\n\n## Getting Started\n\nWelcome to the Switchboard Lottery example. This project showcases how to build a secure and fair lottery system using Switchboard's on-demand randomness solution on Solana.\n\nTo read more about the security guarantees that Switchboard Randomness On-Demand provides, please see: [https://docs.switchboard.xyz/docs/switchboard/switchboard-randomness](https://docs.switchboard.xyz/docs/switchboard/switchboard-randomness)\n\n#### PLEASE ENSURE YOU USE ANCHOR VERSION 0.30.0\n\nConfigure the `anchor.toml` file to point to your solana wallet and the Solana cluster of your choice - Devnet, Mainnet, etc.\n\nThen, build the program:\n\n```bash\nanchor build\n```\n\nAfter building, take note of your program address and insert it in your program `lib.rs` file:\n*Note:* You can view your program address with `anchor keys list`\n```rust\ndeclare_id!(\"[YOUR_PROGRAM_ADDRESS]\");\n```\n\nRebuild your program and deploy:\n```bash\nanchor build\nanchor deploy\nanchor idl init --filepath target/idl/lottery.json YOUR_PROGRAM_ADDRESS\n```\nNote: You may need to use `anchor idl upgrade --filepath target/idl/lottery.json YOUR_PROGRAM_ADDRESS` if you are upgrading the program.\n\n\n\n## About the Lottery\n\nThis example implements a decentralized lottery with the following features:\n\n- Multiple concurrent lotteries identified by unique IDs\n- Configurable entry fees and end times\n- Fair winner selection using Switchboard's verifiable randomness\n- 90% prize pool distribution to winner, 10% to developer\n- Automatic prize claiming system\n\n## Test Setup \u0026 Execution\n\n### Prerequisites\n1. Install Solana Tool Suite (1.17.0 or later)\n2. Install Anchor (0.30.0):\n   ```bash\n   cargo install --git https://github.com/coral-xyz/anchor avm --locked --force\n   avm install 0.30.1\n   avm use 0.30.1\n   ```\n3. Install Node.js\n4. Configure Solana CLI for devnet:\n   ```bash\n   solana config set --url devnet\n   ```\n5. Create a test wallet and fund it:\n   ```bash\n   solana-keygen new -o test-wallet.json\n   solana airdrop 2 test-wallet.json --url devnet\n   ```\n6. Set `wallet=/path/to/test-wallet.json` in `Anchor.toml`\n\nNote: You can get the cli config by using the `solana config get` command.\n\n### Setup Steps\n1. Clone the repository:\n   ```bash\n   git clone \u003crepository-url\u003e\n   cd lottery\n   ```\n\n2. Build the program:\n   ```bash\n   anchor clean  # Clean any existing build artifacts\n   anchor build\n   ```\n\n4. Get your program ID:\n   ```bash\n   anchor keys list\n   ```\n\n5. Update program ID in two places:\n   - In `programs/lottery/src/lib.rs`:\n     ```rust\n     declare_id!(\"YOUR_PROGRAM_ID\");\n     ```\n   - In `Anchor.toml`:\n     ```toml\n     [programs.devnet]\n     lottery = \"YOUR_PROGRAM_ID\"\n     ```\n\n6. Build and deploy:\n   ```bash\n   anchor build\n   anchor deploy\n   ```\n\n7. Initialize IDL:\n   ```bash\n   anchor idl init --filepath target/idl/lottery.json YOUR_PROGRAM_ID\n   ```\n\n### Running Tests\n1. Ensure you have sufficient SOL for testing:\n   ```bash\n   solana balance  # Should show at least 1 SOL\n   ```\n\n2. Run the test suite:\n   ```bash\n   anchor test\n   ```\n\n### Troubleshooting Common Test Issues\n- If tests fail with account errors:\n  ```bash\n  anchor clean\n  anchor build\n  anchor deploy\n  ```\n\n- If you see program ID mismatches:\n  1. Get the correct program ID:\n     ```bash\n     anchor keys list\n     ```\n  2. Update both locations mentioned in Setup Step 5\n  3. Rebuild and redeploy\n\n- If you get IDL errors:\n  ```bash\n  anchor idl upgrade --filepath target/idl/lottery.json YOUR_PROGRAM_ID\n  ```\n\nNote: Always ensure you're on devnet and have sufficient SOL before running tests.\n\n## Debugging\n\n### Common Issues\n\n1. **Account Size Errors / Program Changes**\n   When making significant changes to the program's state or instruction parameters, you may need to:\n   ```bash\n   cargo clean\n   anchor build\n   anchor keys list\n   # Update program ID in lib.rs and Anchor.toml\n   anchor build (again for safe measure)\n   anchor deploy\n   ```\n\n   This is necessary when:\n   - Adding/removing fields in account structs\n   - Changing account sizes\n   - Modifying instruction parameters\n   - Getting program/account size mismatch errors\n   - Encountering IDL inconsistencies\n\n2. **Program ID Mismatches**\n   If you see errors related to program IDs:\n   ```bash\n   anchor keys list  # View your program address\n   # Update declare_id!() in lib.rs\n   # Update Anchor.toml\n   anchor build\n   anchor deploy\n   ```\n\n3. **IDL Updates**\n   After making program changes:\n   ```bash\n   anchor idl init --filepath target/idl/lottery.json YOUR_PROGRAM_ADDRESS\n   # Or if upgrading:\n   anchor idl upgrade --filepath target/idl/lottery.json YOUR_PROGRAM_ADDRESS\n   ```\n\n### Build System Cleaning\n\n**`anchor clean` vs `cargo clean`**:\n- `anchor clean`: Cleans Anchor-specific build artifacts including:\n  - Program keypairs\n  - IDL files\n  - Program deployment info\n  - TypeScript bindings\n  - All Cargo build artifacts\n\n- `cargo clean`: Only cleans Rust/Cargo build artifacts:\n  - Compiled program files\n  - Dependencies\n  - Does not touch Anchor-specific files\n\nUse `anchor clean` when you need a complete reset of your program's build state, especially after structural changes. Use `cargo clean` when you only need to rebuild the Rust code.\n\n#### RPC Config\n\n```bash\nsolana config set --url devnet\n```\n```bash\nsolana config set --url devnet\n```\n\nRPC Providers:\n- https://shyft.to\n- https://quicknode.com/\n- https://helius.dev/\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongan69%2Flotteryprogram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjongan69%2Flotteryprogram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjongan69%2Flotteryprogram/lists"}