{"id":31725527,"url":"https://github.com/bluntbrain/solana-cross-program-invocation","last_synced_at":"2026-07-13T14:31:56.333Z","repository":{"id":311292285,"uuid":"1038740165","full_name":"bluntbrain/solana-cross-program-invocation","owner":"bluntbrain","description":"This project shows how one Solana program calls another program. The main focus is on Cross-Program Invocation (CPI).","archived":false,"fork":false,"pushed_at":"2025-08-23T08:13:12.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-28T22:34:51.696Z","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/bluntbrain.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,"zenodo":null}},"created_at":"2025-08-15T18:29:48.000Z","updated_at":"2025-08-23T08:13:15.000Z","dependencies_parsed_at":"2025-08-24T02:58:47.084Z","dependency_job_id":"7baad787-bca6-4544-9533-3fa29b69d452","html_url":"https://github.com/bluntbrain/solana-cross-program-invocation","commit_stats":null,"previous_names":["bluntbrain/solana-cross-program-invocation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bluntbrain/solana-cross-program-invocation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluntbrain%2Fsolana-cross-program-invocation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluntbrain%2Fsolana-cross-program-invocation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluntbrain%2Fsolana-cross-program-invocation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluntbrain%2Fsolana-cross-program-invocation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluntbrain","download_url":"https://codeload.github.com/bluntbrain/solana-cross-program-invocation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluntbrain%2Fsolana-cross-program-invocation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35426085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-13T02:00:06.543Z","response_time":119,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-10-09T05:49:18.561Z","updated_at":"2026-07-13T14:31:56.313Z","avatar_url":"https://github.com/bluntbrain.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Solana Cross-Program Invocation (CPI) Project\n\n[![Rust](https://img.shields.io/badge/rust-%23000000.svg?style=for-the-badge\u0026logo=rust\u0026logoColor=white)](https://www.rust-lang.org/)\n[![Solana](https://img.shields.io/badge/Solana-000?style=for-the-badge\u0026logo=Solana\u0026logoColor=9945FF)](https://solana.com/)\n[![TypeScript](https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge\u0026logo=typescript\u0026logoColor=white)](https://www.typescriptlang.org/)\n\nThis project shows how one Solana program calls another program. The main focus is on Cross-Program Invocation (CPI).\n\n## How It Works\n\nWe have three programs:\n\n1. **Double Contract** - A simple counter that doubles numbers\n2. **CPI Contract** - Calls the double contract using CPI\n3. **PDA Contract** - Demonstrates Program Derived Addresses (PDAs)\n\nThe CPI contract doesn't do the math itself. Instead, it calls the double contract to handle the counting logic.\n\n## Project Structure\n\n```\ncpi-in-solana/\n├── cpi-contract/\n│   ├── src/lib.rs         # Main CPI program\n│   └── Cargo.toml\n├── double-contract/\n│   ├── src/lib.rs         # Counter program that gets called\n│   └── Cargo.toml\n├── pda-contract/\n│   ├── src/lib.rs         # PDA demonstration program\n│   └── Cargo.toml\n└── client/\n    ├── index.test.ts      # Tests both programs\n    └── package.json\n```\n\n## The CPI Program\n\nThe important part is in `cpi-contract/src/lib.rs`. Here's what it does:\n\n1. Takes two accounts: data account and double contract address\n2. Creates an instruction to call the double contract\n3. Uses `invoke()` to make the CPI call\n4. Passes the data account to the other program\n\n```rust\nlet instruction = Instruction {\n    program_id: *double_contract_address.key,\n    accounts: vec![AccountMeta {\n        is_signer: true,\n        is_writable: true,\n        pubkey: *data_account.key,\n    }],\n    data: vec![],\n};\n\ninvoke(\u0026instruction, \u0026[data_account.clone()])?;\n```\n\nThis is the core of CPI - one program creating an instruction for another program and calling it.\n\n## Setup\n\n```bash\ngit clone \u003cyour-repo\u003e\ncd cpi-in-solana\n\n# Install dependencies\nnpm run setup\n\n# Build both programs\nnpm run build\n\n# Run tests\nnpm run test\n```\n\n## Testing\n\nThe tests show the CPI in action. They:\n\n1. Deploy both programs to a local blockchain\n2. Create accounts and fund them\n3. Call the CPI program\n4. Verify the double contract was executed\n\nYou can see this working in `client/cpi.test.ts`.\n\n## Key Concepts\n\n**Cross-Program Invocation (CPI)**: When one Solana program calls another program during execution.\n\n**invoke()**: The function that makes CPI calls happen. It takes an instruction and the accounts needed.\n\n**invoke_signed()**: Special CPI function that allows programs to sign on behalf of Program Derived Addresses (PDAs). Used when the calling program needs to act as a signer for accounts it owns.\n\n**Program Derived Addresses (PDAs)**: Special accounts owned by programs but without private keys. They're derived deterministically from seeds and the program ID, enabling programs to control accounts programmatically.\n\n**Account Passing**: Accounts get passed from the calling program to the called program. Both programs can read and modify them.\n\n**Program Composition**: Instead of writing one big program, you can split logic into smaller programs that call each other.\n\n## Build Commands\n\n```bash\nnpm run build:cpi      # Build the CPI program\nnpm run build:double   # Build the double counter\nnpm run build:pda      # Build the PDA program\nnpm run build          # Build all programs\nnpm run test           # Run the tests\nnpm run clean          # Clean build files\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluntbrain%2Fsolana-cross-program-invocation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluntbrain%2Fsolana-cross-program-invocation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluntbrain%2Fsolana-cross-program-invocation/lists"}