{"id":14968450,"url":"https://github.com/ironaddicteddog/anchor-escrow","last_synced_at":"2025-07-04T09:37:36.164Z","repository":{"id":39752792,"uuid":"420751289","full_name":"ironaddicteddog/anchor-escrow","owner":"ironaddicteddog","description":"Escrow program implemented in Anchor","archived":false,"fork":false,"pushed_at":"2024-08-29T04:02:22.000Z","size":116,"stargazers_count":191,"open_issues_count":3,"forks_count":78,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T05:07:28.019Z","etag":null,"topics":["anchor","blockchain","rust","solana","typescript","web3"],"latest_commit_sha":null,"homepage":"https://solmeet.gen3.network/notes/intro-to-anchor","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ironaddicteddog.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}},"created_at":"2021-10-24T17:34:42.000Z","updated_at":"2025-03-20T15:01:24.000Z","dependencies_parsed_at":"2024-01-14T17:38:14.730Z","dependency_job_id":null,"html_url":"https://github.com/ironaddicteddog/anchor-escrow","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/ironaddicteddog%2Fanchor-escrow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ironaddicteddog%2Fanchor-escrow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ironaddicteddog%2Fanchor-escrow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ironaddicteddog%2Fanchor-escrow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ironaddicteddog","download_url":"https://codeload.github.com/ironaddicteddog/anchor-escrow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247608153,"owners_count":20965952,"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":["anchor","blockchain","rust","solana","typescript","web3"],"created_at":"2024-09-24T13:39:56.638Z","updated_at":"2025-04-07T07:14:24.341Z","avatar_url":"https://github.com/ironaddicteddog.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Anchor Example: Escrow Program\n\n\u003e See this [doc](https://solmeet.gen3.network/notes/intro-to-anchor) for more implementation details\n\n## Overview\n\nSince this program is extended from the original [Escrow Program](https://github.com/paul-schaaf/solana-escrow), I assumed you have gone through the [original blog post](https://paulx.dev/blog/2021/01/14/programming-on-solana-an-introduction/#instruction-rs-part-1-general-code-structure-and-the-beginning-of-the-escrow-program-flow) at least once.\n\nHowever, there is one major difference between this exmaple and the original Escrow program: Instead of letting initializer create a token account to be reset to a PDA authority, we create `Vault Authority(PDA)`'s associated token account (ATA) directly without transferring authority.\n\n#### Initialize\n\n![](https://hackmd.io/_uploads/Hkn1gdtuj.png)\n\n`Initializer` can send a transaction to the escrow program to initialize the Vault. In this transaction, two new accounts: `Vault Authority's ATA` and `Escrow State`, will be created and tokens (Token A) to be exchanged will be transferred from `Initializer` to `Vault`(short for vault authority's ATA).\n\n#### Cancel\n\n![](https://hackmd.io/_uploads/ry0GNdKdo.png)\n\n`Initializer` can also send a transaction to the escrow program to cancel the demand of escrow. The tokens will be transferred back to the `Initializer` and both `Vault` and `Escrow State` will be closed in this case.\n\n#### Exchange\n\n![](https://hackmd.io/_uploads/HkhNE_tdi.png)\n\n`Taker` can send a transaction to the escrow to exchange Token B for Token A. First, tokens (Token B) will be transferred from `Taker` to `Initializer`. Afterward, the tokens (Token A) kept in the Vault will be transferred to `Taker`. Finally, both `Vault` and `Escrow State` will be closed.\n\n## Install, Build, Deploy and Test\n\nLet's run the test once to see what happens.\n\n### Install `anchor`\n\nFirst, make sure that `anchor` is installed:\n\nInstall `avm`:\n\n```bash\n$ cargo install --git https://github.com/coral-xyz/anchor avm --locked --force\n...\n```\n\nInstall latest `anchor` version:\n\n```bash\n$ avm install 0.27.0\n...\n$ avm use 0.27.0\n...\n```\n\n\u003e If you haven't installed `cargo`, please refer to this [doc](https://book.solmeet.dev/notes/solana-starter-kit#install-rust-and-solana-cli) for installation steps.\n\n#### Extra Dependencies on Linux (Optional)\n\nYou may have to install some extra dependencies on Linux (ex. Ubuntu):\n\n```bash\n$ sudo apt-get update \u0026\u0026 sudo apt-get upgrade \u0026\u0026 sudo apt-get install -y pkg-config build-essential libudev-dev\n...\n```\n\n#### Verify the Installation\n\nCheck if Anchor is successfully installed:\n\n```bash\n$ anchor --version\nanchor-cli 0.27.0\n```\n\n### Install Dependencies\n\nNext, install dependencies:\n\n```\n$ yarn\n```\n\n### Build `anchor-escrow`\n\n#### Update `program_id`\n\nGet the public key of the deploy key. This keypair is generated automatically so a different key is exptected:\n\n```bash\n$ anchor keys list\nanchor_escrow: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS\n```\n\nReplace the default value of `program_id` with this new value:\n\n```toml\n# Anchor.toml\n\n[programs.localnet]\nanchor_escrow = \"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS\"\n\n...\n```\n\n```rust\n// lib.rs\n\n...\n\ndeclare_id!(\"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS\");\n\n...\n```\n\nBuild the program:\n\n```\n$ anchor build\n```\n\n### Deploy `anchor-escrow`\n\nLet's deploy the program. Notice that `anchor-escrow` will be deployed on a [mainnet-fork](https://github.com/DappioWonderland/solana) test validator run by Dappio:\n\n```\n$ solana config set --url localhost\n...\n```\n\n```\n$ anchor deploy\n...\n\nProgram Id: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS\n\nDeploy success\n```\n\nFinally, run the test:\n\n```\n$ anchor test --skip-deploy --skip-build --skip-local-validator\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fironaddicteddog%2Fanchor-escrow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fironaddicteddog%2Fanchor-escrow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fironaddicteddog%2Fanchor-escrow/lists"}