{"id":26943560,"url":"https://github.com/thrishank/native-escrow","last_synced_at":"2026-05-02T04:41:06.526Z","repository":{"id":285515850,"uuid":"958361280","full_name":"thrishank/native-escrow","owner":"thrishank","description":"escrow contract implementaion in native rust","archived":false,"fork":false,"pushed_at":"2025-04-01T06:19:14.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T07:27:15.300Z","etag":null,"topics":["rust","solana"],"latest_commit_sha":null,"homepage":"","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/thrishank.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":"2025-04-01T04:27:11.000Z","updated_at":"2025-04-01T06:19:17.000Z","dependencies_parsed_at":"2025-04-01T07:27:33.174Z","dependency_job_id":"a4fdf7be-26c1-49ed-a010-f0550363d8d7","html_url":"https://github.com/thrishank/native-escrow","commit_stats":null,"previous_names":["thrishank/native-escrow"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thrishank/native-escrow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thrishank%2Fnative-escrow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thrishank%2Fnative-escrow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thrishank%2Fnative-escrow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thrishank%2Fnative-escrow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thrishank","download_url":"https://codeload.github.com/thrishank/native-escrow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thrishank%2Fnative-escrow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32523428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"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":["rust","solana"],"created_at":"2025-04-02T17:15:50.127Z","updated_at":"2026-05-02T04:41:06.511Z","avatar_url":"https://github.com/thrishank.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Native Escrow\n\n- [Accounts](#accounts)\n- [Make Instruction](#make-instruction)\n- [Take Instruction](#take-instruction)\n- [Refund Instruction](#refund-instruction)\n- [Sign and Send Transaction](#sign-and-send-transaction)\n- [Cargo.toml for Testing](#cargotoml-for-testing)\n\n---\n\n## Accounts\n\n```rust\nlet program_id: Pubkey = Pubkey::from_str(\"6YwczHkrhMkuajdvcE6CqcanGzxrZDtwhdiQ6PPU98no\")?;\n\nlet maker = Pubkey::from_str(\"\")?;\nlet token_mint_a = Pubkey::from_str(\"\")?;\nlet token_mint_b = Pubkey::from_str(\"\")?;\nlet maker_token_account_a = Pubkey::from_str(\"\")?;\nlet maker_token_account_b = get_associated_token_address(\u0026maker, \u0026token_mint_b);\n\nlet taker_key = Pubkey::from_str(\"\")?;\nlet taker_token_account_a = get_associated_token_address(\u0026taker_key, \u0026token_mint_a);\nlet taker_token_account_b = get_associated_token_address(\u0026taker_key, \u0026token_mint_b);\n\n\nlet escrow = Pubkey::find_program_address(\n    \u0026[b\"token-escrow\", maker.as_ref(), \u0026id.to_be_bytes()],\n    \u0026program_id,\n).0;\n\nlet escrow_token_ata = get_associated_token_address(\u0026escrow, \u0026token_mint_a);\n\nlet token_program = Pubkey::from_str(\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\")?;\nlet associated_token_program = Pubkey::from_str(\"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL\")?;\nlet system_program = Pubkey::from_str(\"11111111111111111111111111111111\")?;\n```\n\n## Make Instruction\n\n```rust\n#[derive(BorshSerialize)]\npub enum Instruction { // order of the instruction matters\n  Make {id: u64, deposit: u64, recieve: u64},\n  Take {},\n  Refund {}\n}\n// serialize the instruction\nlet mut instr_in_bytes: Vec\u003cu8\u003e = Vec::new();\n\nlet id: u64 = 23424; // random number can be used only once\nlet init_data = Instructions::Init {\n    id,\n    deposit: 10_000_000_000,\n    receive: 20_000_000_000,\n};\n\ninit_data.serialize(\u0026mut instr_in_bytes)?;\n\n// accounts must be in the same order\nlet accounts: Vec\u003cAccountMeta\u003e = vec![\n    AccountMeta::new(maker, true),\n    AccountMeta::new(token_mint_a, false),\n    AccountMeta::new(token_mint_b, false),\n    AccountMeta::new(maker_token_account_a, false),\n    AccountMeta::new(escrow, false),\n    AccountMeta::new(escrow_token_ata, false),\n    AccountMeta::new_readonly(token_program, false),\n    AccountMeta::new_readonly(associated_token_program, false),\n    AccountMeta::new_readonly(system_program, false),\n];\n\nlet maker_keypair: Keypair = Keypair::from_base58_string(\"private bs58 string\");\n\nsign_and_send_tx(instr_in_bytes, accounts, \u0026maker_keypair);\n```\n\n## Take Instruction\n\n```rust\nlet take_accounts: Vec\u003cAccountMeta\u003e = vec![\n    AccountMeta::new(maker, false),\n    AccountMeta::new(taker_key, true),\n    AccountMeta::new(token_mint_a, false),\n    AccountMeta::new(token_mint_b, false),\n    AccountMeta::new(escrow, false),\n    AccountMeta::new(escrow_token_ata, false),\n    AccountMeta::new(taker_token_account_a, false),\n    AccountMeta::new(taker_token_account_b, false),\n    AccountMeta::new(maker_token_account_b, false),\n    AccountMeta::new_readonly(token_program, false),\n    AccountMeta::new_readonly(associated_token_program, false),\n    AccountMeta::new_readonly(system_program, false),\n];\n\nlet take = Instructions::Take {};\nlet mut take_ix_data: Vec\u003cu8\u003e = Vec::new();\ntake.serialize(\u0026mut take_ix_data).unwrap();\n\nlet taker = Keypair::from_base58_string(\"taker private key\");\n\nsign_and_send_tx(take_ix_data, take_accounts, \u0026taker);\n```\n\n## Refund Instruction\n\n```rust\nlet refund = Instructions::Refund {};\nlet mut refund_ix_data: Vec\u003cu8\u003e = Vec::new();\nrefund.serialize(\u0026mut refund_ix_data).unwrap();\n\nlet refund_accounts: Vec\u003cAccountMeta\u003e = vec![\n    AccountMeta::new(maker, true),\n    AccountMeta::new(token_mint_a, false),\n    AccountMeta::new(escrow, false),\n    AccountMeta::new(escrow_token_ata, false),\n    AccountMeta::new(maker_token_account_a, false),\n    AccountMeta::new_readonly(token_program, false),\n    AccountMeta::new_readonly(system_program, false),\n];\n\nsign_and_send_tx(refund_ix_data, refund_accounts, \u0026maker_keypair);\n```\n\n## Sign and send transaction\n\n```rust\nfn sign_and_send_tx(instruction_data: Vec\u003cu8\u003e, accounts: Vec\u003cAccountMeta\u003e, payer: \u0026Keypair) {\n    let rpc_client: RpcClient = RpcClient::new(\"https://api.devnet.solana.com\");\n\n    let program_id: Pubkey =\n        Pubkey::from_str(\"6YwczHkrhMkuajdvcE6CqcanGzxrZDtwhdiQ6PPU98no\").expect(\"Invalid pubkey\");\n\n    let recent_blockhash = rpc_client\n        .get_latest_blockhash()\n        .expect(\"Failed to get blockhash\");\n\n    let ix = Instruction::new_with_bytes(program_id, \u0026instruction_data, accounts);\n\n    let tx = Transaction::new_signed_with_payer(\n        \u0026[ix],\n        Some(\u0026payer.pubkey()),\n        \u0026[\u0026payer],\n        recent_blockhash,\n    );\n\n    let signature = rpc_client\n        .send_and_confirm_transaction(\u0026tx)\n        .expect(\"Transaction failed\");\n    println!(\"Transaction successful! Signature: {}\", signature);\n}\n```\n\n## Cargo.toml for testing\n\n```toml\n[package]\nname = \"rust\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\nsolana-sdk = \"~1.18.11\"\nsolana-client = \"~1.18.11\"\nborsh = \"1.5\"\nspl-associated-token-account = { version = \"3.0.4\", features = [\n  \"no-entrypoint\",\n] }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthrishank%2Fnative-escrow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthrishank%2Fnative-escrow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthrishank%2Fnative-escrow/lists"}