{"id":25415787,"url":"https://github.com/deanmlittle/solana-idlgen","last_synced_at":"2025-10-31T08:31:44.681Z","repository":{"id":158467242,"uuid":"634056605","full_name":"deanmlittle/solana-idlgen","owner":"deanmlittle","description":"A macro to generate Rust code from an IDL to interact with onchain programs","archived":false,"fork":false,"pushed_at":"2024-06-14T04:16:04.000Z","size":21,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-06-14T05:28:44.425Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deanmlittle.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":"2023-04-28T23:27:06.000Z","updated_at":"2024-06-14T05:28:48.074Z","dependencies_parsed_at":"2024-06-14T05:28:47.080Z","dependency_job_id":"04988035-84f1-4624-9061-2fc84d0e2068","html_url":"https://github.com/deanmlittle/solana-idlgen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deanmlittle%2Fsolana-idlgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deanmlittle%2Fsolana-idlgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deanmlittle%2Fsolana-idlgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deanmlittle%2Fsolana-idlgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deanmlittle","download_url":"https://codeload.github.com/deanmlittle/solana-idlgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239154773,"owners_count":19590766,"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-02-16T15:52:33.097Z","updated_at":"2025-10-31T08:31:44.375Z","avatar_url":"https://github.com/deanmlittle.png","language":"Rust","funding_links":[],"categories":["Solana Development Tools"],"sub_categories":["Notes"],"readme":"# DEPRECATED\nIt is recommened to instead use my new tool, [idlgen](https://github.com/deanmlittle/idlgen). It is Anchor 0.29.0 and Anchor 0.30.0 IDL compatible and creates a production-ready crate with feature flags enabling you to do CPI, Introspection and RPC without having to include your program as a dependency.\n\n# Solana IDLGen\nIDLgen generates a code scaffold for calling instructions for custom Solana program in Rust based upon its IDL.\n\nSimply insert a compatible IDL into the `idlgen!()` macro and you can generate:\n\n- A program struct\n- An `impl` containing callable functions to generate valid `Instructions`, as well as signed and unsigned `Transactions`\n- All required data `structs` for said instructions with Borsh serialization implemented\n\n### Quickstart\n\nAdd `solana-sdk` to your Cargo.toml then consume the macro like so:\n\n```rs\nuse solana_idlgen::idlgen;\nidlgen!({\n    \"version\": \"0.1.0\",\n    \"name\": \"example_program\",\n    \"instructions\": [{\n        \"name\": \"example_instrution\",\n        \"accounts\": [{\n            \"name\": \"signer\",\n            \"isMut\": true,\n            \"isSigner\": true\n        }, {\n            \"name\": \"exampleAccount\",\n            \"isMut\": true,\n            \"isSigner\": false\n        }, {\n            \"name\": \"systemProgram\",\n            \"isMut\": false,\n            \"isSigner\": false\n        }],\n        \"args\": [{\n            \"name\": \"name\",\n            \"type\": \"bytes\"\n        }]\n    }],\n    \"accounts\": [{\n        \"name\": \"ExampleAccount\",\n        \"type\": {\n            \"kind\": \"struct\",\n            \"fields\": [{\n                \"name\": \"name\",\n                \"type\": \"bytes\"\n            }]\n        }\n    }],\n    \"metadata\": {\n        \"address\": \"11111111111111111111111111111111\"\n    }\n});\n```\n\nThis will generate:\n```rs\nuse borsh::{BorshSerialize, to_vec};\nuse solana_sdk::{\n    hash::Hash,\n    instruction::{AccountMeta, Instruction},\n    message::Message,\n    pubkey::Pubkey,\n    signature::{Keypair, Signer},\n    transaction::Transaction,\n};\n\n#[derive(Debug, BorshSerialize)]\npub struct ExampleArgs {\n    pub name: Vec\u003cu8\u003e,\n}\n\n#[derive(Debug)]\npub struct ExampleProgram {}\n\nimpl ExampleProgram {\n    pub fn id() -\u003e Pubkey {\n        Pubkey::new_from_array([\n            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n            0, 0, 0,\n        ])\n    }\n\n    pub fn example_ix_from_bytes(accounts: \u0026[\u0026Pubkey; 3usize], bytes: \u0026[u8]) -\u003e Instruction {\n        let account_meta: Vec\u003cAccountMeta\u003e = vec![\n            AccountMeta::new(accounts[0usize].clone(), true),\n            AccountMeta::new(accounts[1usize].clone(), false),\n            AccountMeta::new_readonly(accounts[2usize].clone(), false),\n        ];\n        Instruction::new_with_bytes(Self::id(), \u0026bytes, account_meta)\n    }\n\n    pub fn example_ix_from_data(accounts: \u0026[\u0026Pubkey; 3usize], args: \u0026ExampleArgs) -\u003e Instruction {\n        let mut data_bytes: Vec\u003cu8\u003e = vec![189, 174, 40, 25, 180, 44, 109, 58];\n        data_bytes.extend_from_slice(\u0026to_vec(\u0026args).expect(\"Unable to serialize data\"));\n        Self::example_ix_from_bytes(accounts, \u0026data_bytes)\n    }\n\n    pub fn example(\n        accounts: \u0026[\u0026Pubkey; 3usize],\n        args: \u0026ExampleArgs,\n        payer: Option\u003c\u0026Pubkey\u003e,\n        signers: \u0026[\u0026Keypair; 1usize],\n        blockhash: Hash,\n    ) -\u003e Transaction {\n        let ix = Self::example_ix_from_data(accounts, args);\n        Transaction::new_signed_with_payer(\u0026[ix], payer, signers, blockhash)\n    }\n\n    pub fn example_unsigned(\n        accounts: \u0026[\u0026Pubkey; 3usize],\n        args: \u0026ExampleArgs,\n        payer: Option\u003c\u0026Pubkey\u003e,\n    ) -\u003e Transaction {\n        let ix = Self::example_ix_from_data(accounts, args);\n        Transaction::new_unsigned(Message::new(\u0026[ix], payer))\n    }\n    pub fn derive_program_address(seeds: \u0026[\u0026[u8]]) -\u003e Pubkey {\n        Self::derive_program_address_and_bump(seeds).0\n    }\n    pub fn derive_program_address_and_bump(seeds: \u0026[\u0026[u8]]) -\u003e (Pubkey, u8) {\n        Pubkey::find_program_address(seeds, \u0026Self::id())\n    }\n}\n\n```\n\nYou can then generate PDAs and call instructions from your program like so:\n\n```rs\n\n// Connect to devnet RPC endpoint\nlet rpc_client = RpcClient::new(\"https://api.devnet.solana.com\".to_string());\n\n// Get the recent blockhash\nlet blockhash = rpc_client.get_latest_blockhash().unwrap();\n\nlet signer = Keypair::new();\n\n// Derive the example PDA from ExampleProgram\nlet example = ExampleProgram::derive_program_address(\u0026[\u0026b\"example\".as_ref(), \u0026signer.pubkey().as_ref()]);\n\n// Example instruction args\nlet args = ExampleArgs {\n    name: b\"anatoly\".to_vec()\n};\n\n// Call the \"example\" instruction of ExampleProgram\nExampleProgram::example(\n    \u0026[\n        \u0026signer.pubkey(),\n        \u0026example,\n        \u0026system_program::id()\n    ],\n    \u0026args,\n    Some(\u0026signer.pubkey()),\n    \u0026[\n        \u0026signer\n    ],\n    blockhash\n);\n```\n\n### Caveats\n- you must add the `solana-sdk` and `borsh` with `derive` feature enabled to the Cargo.toml of the package where you consume `idlgen`\n- you must populate the optional IDL `metadata -\u003e address` field to get the Program ID\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeanmlittle%2Fsolana-idlgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeanmlittle%2Fsolana-idlgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeanmlittle%2Fsolana-idlgen/lists"}