{"id":42606309,"url":"https://github.com/faremeter/solana-payment-program-example","last_synced_at":"2026-01-29T01:52:45.114Z","repository":{"id":296878647,"uuid":"992227611","full_name":"faremeter/solana-payment-program-example","owner":"faremeter","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-03T13:38:32.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-03T14:47:00.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faremeter.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2025-05-28T20:23:06.000Z","updated_at":"2025-07-03T13:38:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"d86e6c68-1488-4980-adbc-29c2d3d78d69","html_url":"https://github.com/faremeter/solana-payment-program-example","commit_stats":null,"previous_names":["faremeter/solana-payment-program-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/faremeter/solana-payment-program-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faremeter%2Fsolana-payment-program-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faremeter%2Fsolana-payment-program-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faremeter%2Fsolana-payment-program-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faremeter%2Fsolana-payment-program-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faremeter","download_url":"https://codeload.github.com/faremeter/solana-payment-program-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faremeter%2Fsolana-payment-program-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28860059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T22:56:21.783Z","status":"ssl_error","status_checked_at":"2026-01-28T22:56:00.861Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-29T01:52:45.050Z","updated_at":"2026-01-29T01:52:45.107Z","avatar_url":"https://github.com/faremeter.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solana Payment-Gated API System\n\n## Concept\n\nThis system creates a **Solana program** that manages micropayments for API access. Here's how it works:\n\n1. **Payment Creation**: When a user wants to access a protected endpoint, they create a payment transaction that:\n   - Transfers SOL to the API provider\n   - Creates a **Payment account** (PDA) that stores payment metadata\n   - Uses a unique nonce to prevent duplicate payments\n\n2. **Settlement with Race Condition Protection**: When the server processes the payment, it immediately settles it using an admin transaction that:\n   - **Uses a unique settle nonce** - this is crucial for preventing race conditions\n   - Multiple settlement attempts will fail because only one can successfully close the account\n   - **Returns the rent** from the Payment account back to the original payer\n   - Ensures each payment can only be settled once\n\n3. **Rent Recovery**: The Payment account requires rent (~0.002 SOL) to exist on-chain. When settled, this rent is automatically returned to the original payer, so they only pay the actual service fee.\n\n## 🔒 Race Condition Prevention\n\nThe **settle nonce** is key to preventing race conditions:\n\n```rust\n// Each settlement transaction uses a unique nonce\npub fn settle_payment(\n    ctx: Context\u003cSettlePayment\u003e,\n    original_payer: Pubkey,\n    payment_nonce: [u8; 32],  // Original payment nonce\n    settle_nonce: [u8; 32],   // UNIQUE settle nonce - prevents race\n) -\u003e Result\u003c()\u003e\n```\n\nExample createPayment tx: https://solscan.io/tx/4F1kPoz3L6JqWcUM53cGMZjvYb41TuzqZbAXrXDYQmF6HWNQB2M9WFBbXzdE56GFCNudieAKH5tfJzk6u51EMUF?cluster=devnet\n\nExample settlePayment tx: https://solscan.io/tx/3UZNTyG7QsceTCBmJmTHE8Fiah6TeJpzopKzCcLNciXHrtTKUrZQub9322AWBuuxba2q1zsN4NXp6Pja6podNfrH?cluster=devnet","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaremeter%2Fsolana-payment-program-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaremeter%2Fsolana-payment-program-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaremeter%2Fsolana-payment-program-example/lists"}