</code></pre></div><p>Builds programs in the workspace targeting Solana's BPF runtime and emitting IDLs in the <code>target/idl</code> directory.</p><divclass="language- extra-class"><preclass="language-text"><code>anchor build --verifiable
</code></pre></div><p>Runs the build inside a docker image so that the output binary is deterministic (assuming a Cargo.lock file is used). This command must be run from within a single crate subdirectory within the workspace. For example, <code>programs/<my-program>/</code>.</p><h2id="cluster"><ahref="#cluster"class="header-anchor">#</a> Cluster</h2><h3id="cluster-list"><ahref="#cluster-list"class="header-anchor">#</a> Cluster list</h3><divclass="language- extra-class"><preclass="language-text"><code>anchor cluster list
</code></pre></div><p>Deploys all programs in the workspace to the configured cluster.</p><divclass="custom-block tip"><pclass="custom-block-title">Note</p><p>This is different from the <code>solana program deploy</code> command, because everytime it's run
it will generate a <em>new</em> program address.</p></div><h2id="expand"><ahref="#expand"class="header-anchor">#</a> Expand</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor expand
</code></pre></div><p>If run inside a program folder, expands the macros of the program.</p><p>If run in the workspace but outside a program folder, expands the macros of the workspace.</p><p>If run with the <code>--program-name</code> option, expand only the given program.</p><h2id="idl"><ahref="#idl"class="header-anchor">#</a> Idl</h2><p>The <code>idl</code> subcommand provides commands for interacting with interface definition files.
It's recommended to use these commands to store an IDL on chain, at a deterministic
address, as a function of nothing but the the program's ID. This
allows us to generate clients for a program using nothing but the program ID.</p><h3id="idl-init"><ahref="#idl-init"class="header-anchor">#</a> Idl Init</h3><divclass="language- extra-class"><preclass="language-text"><code>anchor idl init -f <target/idl/program.json><program-id>
</code></pre></div><p>Creates an idl account, writing the given <code><target/idl/program.json></code> file into a program owned account. By default, the size of the account is double the size of the IDL,
allowing room for growth in case the idl needs to be upgraded in the future.</p><h3id="idl-fetch"><ahref="#idl-fetch"class="header-anchor">#</a> Idl Fetch</h3><divclass="language- extra-class"><preclass="language-text"><code>anchor idl fetch -o <out-file.json><program-id>
</code></pre></div><p>Fetches an IDL from the configured blockchain. For example, make sure
your <code>Anchor.toml</code> is pointing to the <code>mainnet</code> cluster and run</p><divclass="language- extra-class"><preclass="language-text"><code>anchor idl fetch GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv
</code></pre></div><p>Erases the IDL account's authority so that upgrades can no longer occur. The
configured wallet must be the current authority.</p><h3id="idl-upgrade"><ahref="#idl-upgrade"class="header-anchor">#</a> Idl Upgrade</h3><divclass="language- extra-class"><preclass="language-text"><code>anchor idl upgrade <program-id> -f <target/idl/program.json>
</code></pre></div><p>Upgrades the IDL file on chain to the new <code>target/idl/program.json</code> idl.
The configured wallet must be the current authority.</p><divclass="language- extra-class"><preclass="language-text"><code>anchor idl set-authority -n <new-authority> -p <program-id>
</code></pre></div><p>Sets a new authority on the IDL account. Both the <code>new-authority</code> and <code>program-id</code>
must be encoded in base 58.</p><h2id="init"><ahref="#init"class="header-anchor">#</a> Init</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor init
</code></pre></div><p>Initializes a project workspace with the following structure.</p><ul><li><code>Anchor.toml</code>: Anchor configuration file.</li><li><code>Cargo.toml</code>: Rust workspace configuration file.</li><li><code>package.json</code>: JavaScript dependencies file.</li><li><code>programs/</code>: Directory for Solana program crates.</li><li><code>app/</code>: Directory for your application frontend.</li><li><code>tests/</code>: Directory for JavaScript integration tests.</li><li><code>migrations/deploy.js</code>: Deploy script.</li></ul><h2id="migrate"><ahref="#migrate"class="header-anchor">#</a> Migrate</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor migrate
</code></pre></div><p>Runs the deploy script located at <code>migrations/deploy.js</code>, injecting a provider configured
from the workspace's <code>Anchor.toml</code>. For example,</p><divclass="language-javascript extra-class"><preclass="language-javascript"><code><spanclass="token comment">// File: migrations/deploys.js</span>
<spanclass="token comment">// Add your deploy script here.</span>
<spanclass="token punctuation">}</span>
</code></pre></div><p>Migrations are a new feature
and only support this simple deploy script at the moment.</p><h2id="new"><ahref="#new"class="header-anchor">#</a> New</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor new <program-name>
</code></pre></div><p>Creates a new program in the workspace's <code>programs/</code> directory initialized with boilerplate.</p><h2id="test"><ahref="#test"class="header-anchor">#</a> Test</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor test
</code></pre></div><p>Run an integration test suit against the configured cluster, deploying new versions
of all workspace programs before running them.</p><p>If the configured network is a localnet, then automatically starts the localnetwork and runs
the test.</p><divclass="custom-block tip"><pclass="custom-block-title">Note</p><p>Be sure to shutdown any other local validators, otherwise <code>anchor test</code> will fail to run.</p><p>If you'd prefer to run the program against your local validator use <code>anchor test --skip-local-validator</code>.</p></div><p>When running tests we stream program logs to <code>.anchor/program-logs/<address>.<program-name>.log</code></p><divclass="custom-block tip"><pclass="custom-block-title">Note</p><p>The Anchor workflow <ahref="https://www.parity.io/paritys-checklist-for-secure-smart-contract-development/"target="_blank"rel="noopener noreferrer">recommends<span><svgxmlns="http://www.w3.org/2000/svg"aria-hidden="true"focusable="false"x="0px"y="0px"viewBox="0 0 100 100"width="15"height="15"class="icon outbound"><pathfill="currentColor"d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygonfill="currentColor"points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><spanclass="sr-only">(opens new window)</span></span></a>
to test your program using integration tests in a language other
than Rust to make sure that bugs related to syntax misunderstandings
are coverable with tests and not just replicated in tests.</p></div><h2id="upgrade"><ahref="#upgrade"class="header-anchor">#</a> Upgrade</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor upgrade <target/deploy/program.so> --program-id <program-id>
</code></pre></div><p>Uses Solana's upgradeable BPF loader to upgrade the on chain program code.</p><h2id="verify"><ahref="#verify"class="header-anchor">#</a> Verify</h2><divclass="language- extra-class"><preclass="language-text"><code>anchor verify <program-id>
</code></pre></div><p>Verifies the on-chain bytecode matches the locally compiled artifact.</p></div><footerclass="page-edit"><!----><!----></footer><divclass="page-nav"><pclass="inner"><spanclass="prev">