diff --git a/404.html b/404.html index d4f81e1d..e825fadf 100644 --- a/404.html +++ b/404.html @@ -10,11 +10,11 @@ - +
- + diff --git a/assets/js/10.9b75e9f0.js b/assets/js/10.99d917b5.js similarity index 99% rename from assets/js/10.9b75e9f0.js rename to assets/js/10.99d917b5.js index a2628d8e..352d6bba 100644 --- a/assets/js/10.9b75e9f0.js +++ b/assets/js/10.99d917b5.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[10],{406:function(t,a,e){"use strict";e.r(a);var s=e(29),r=Object(s.a)({},(function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"commands"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#commands"}},[t._v("#")]),t._v(" Commands")]),t._v(" "),e("p",[t._v("A CLI is provided to support building and managing an Anchor workspace.\nFor a comprehensive list of commands and options, run "),e("code",[t._v("anchor -h")]),t._v(" on any\nof the following subcommands.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor-cli\n\nUSAGE:\n anchor \n\nFLAGS:\n -h, --help Prints help information\n -V, --version Prints version information\n\nSUBCOMMANDS:\n build Builds the workspace\n cluster Cluster commands\n deploy Deploys each program in the workspace\n expand Expands the macros of a program or the workspace\n help Prints this message or the help of the given subcommand(s)\n idl Commands for interacting with interface definitions\n init Initializes a workspace\n migrate Runs the deploy migration script\n new Creates a new program\n test Runs integration tests against a localnetwork\n upgrade Upgrades a single program. The configured wallet must be the upgrade authority\n verify Verifies the on-chain bytecode matches the locally compiled artifact. Run this\n command inside a program subdirectory, i.e., in the dir containing the program's\n Cargo.toml\n")])])]),e("h2",{attrs:{id:"build"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#build"}},[t._v("#")]),t._v(" Build")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor build\n")])])]),e("p",[t._v("Builds programs in the workspace targeting Solana's BPF runtime and emitting IDLs in the "),e("code",[t._v("target/idl")]),t._v(" directory.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor build --verifiable\n")])])]),e("p",[t._v("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, "),e("code",[t._v("programs//")]),t._v(".")]),t._v(" "),e("h2",{attrs:{id:"cluster"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cluster"}},[t._v("#")]),t._v(" Cluster")]),t._v(" "),e("h3",{attrs:{id:"cluster-list"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cluster-list"}},[t._v("#")]),t._v(" Cluster list")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor cluster list\n")])])]),e("p",[t._v("This lists cluster endpoints:")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("Cluster Endpoints:\n\n* Mainnet - https://solana-api.projectserum.com\n* Mainnet - https://api.mainnet-beta.solana.com\n* Devnet - https://api.devnet.solana.com\n* Testnet - https://api.testnet.solana.com\n")])])]),e("h2",{attrs:{id:"deploy"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#deploy"}},[t._v("#")]),t._v(" Deploy")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor deploy\n")])])]),e("p",[t._v("Deploys all programs in the workspace to the configured cluster.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("This is different from the "),e("code",[t._v("solana program deploy")]),t._v(" command, because everytime it's run\nit will generate a "),e("em",[t._v("new")]),t._v(" program address.")])]),t._v(" "),e("h2",{attrs:{id:"expand"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#expand"}},[t._v("#")]),t._v(" Expand")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor expand\n")])])]),e("p",[t._v("If run inside a program folder, expands the macros of the program.")]),t._v(" "),e("p",[t._v("If run in the workspace but outside a program folder, expands the macros of the workspace.")]),t._v(" "),e("p",[t._v("If run with the "),e("code",[t._v("--program-name")]),t._v(" option, expand only the given program.")]),t._v(" "),e("h2",{attrs:{id:"idl"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl"}},[t._v("#")]),t._v(" Idl")]),t._v(" "),e("p",[t._v("The "),e("code",[t._v("idl")]),t._v(" subcommand provides commands for interacting with interface definition files.\nIt's recommended to use these commands to store an IDL on chain, at a deterministic\naddress, as a function of nothing but the the program's ID. This\nallows us to generate clients for a program using nothing but the program ID.")]),t._v(" "),e("h3",{attrs:{id:"idl-init"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-init"}},[t._v("#")]),t._v(" Idl Init")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl init -f \n")])])]),e("p",[t._v("Creates an idl account, writing the given "),e("code",[t._v("")]),t._v(" file into a program owned account. By default, the size of the account is double the size of the IDL,\nallowing room for growth in case the idl needs to be upgraded in the future.")]),t._v(" "),e("h3",{attrs:{id:"idl-fetch"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-fetch"}},[t._v("#")]),t._v(" Idl Fetch")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl fetch -o \n")])])]),e("p",[t._v("Fetches an IDL from the configured blockchain. For example, make sure\nyour "),e("code",[t._v("Anchor.toml")]),t._v(" is pointing to the "),e("code",[t._v("mainnet")]),t._v(" cluster and run")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl fetch GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv\n")])])]),e("h3",{attrs:{id:"idl-authority"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-authority"}},[t._v("#")]),t._v(" Idl Authority")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl authority \n")])])]),e("p",[t._v("Outputs the IDL account's authority. This is the wallet that has the ability to\nupdate the IDL.")]),t._v(" "),e("h3",{attrs:{id:"idl-erase-authority"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-erase-authority"}},[t._v("#")]),t._v(" Idl Erase Authority")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl erase-authority -p \n")])])]),e("p",[t._v("Erases the IDL account's authority so that upgrades can no longer occur. The\nconfigured wallet must be the current authority.")]),t._v(" "),e("h3",{attrs:{id:"idl-upgrade"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-upgrade"}},[t._v("#")]),t._v(" Idl Upgrade")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl upgrade -f \n")])])]),e("p",[t._v("Upgrades the IDL file on chain to the new "),e("code",[t._v("target/idl/program.json")]),t._v(" idl.\nThe configured wallet must be the current authority.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl set-authority -n -p \n")])])]),e("p",[t._v("Sets a new authority on the IDL account. Both the "),e("code",[t._v("new-authority")]),t._v(" and "),e("code",[t._v("program-id")]),t._v("\nmust be encoded in base 58.")]),t._v(" "),e("h2",{attrs:{id:"init"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#init"}},[t._v("#")]),t._v(" Init")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor init\n")])])]),e("p",[t._v("Initializes a project workspace with the following structure.")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("Anchor.toml")]),t._v(": Anchor configuration file.")]),t._v(" "),e("li",[e("code",[t._v("Cargo.toml")]),t._v(": Rust workspace configuration file.")]),t._v(" "),e("li",[e("code",[t._v("package.json")]),t._v(": JavaScript dependencies file.")]),t._v(" "),e("li",[e("code",[t._v("programs/")]),t._v(": Directory for Solana program crates.")]),t._v(" "),e("li",[e("code",[t._v("app/")]),t._v(": Directory for your application frontend.")]),t._v(" "),e("li",[e("code",[t._v("tests/")]),t._v(": Directory for JavaScript integration tests.")]),t._v(" "),e("li",[e("code",[t._v("migrations/deploy.js")]),t._v(": Deploy script.")])]),t._v(" "),e("h2",{attrs:{id:"migrate"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#migrate"}},[t._v("#")]),t._v(" Migrate")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor migrate\n")])])]),e("p",[t._v("Runs the deploy script located at "),e("code",[t._v("migrations/deploy.js")]),t._v(", injecting a provider configured\nfrom the workspace's "),e("code",[t._v("Anchor.toml")]),t._v(". For example,")]),t._v(" "),e("div",{staticClass:"language-javascript extra-class"},[e("pre",{pre:!0,attrs:{class:"language-javascript"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// File: migrations/deploys.js")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" anchor "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("require")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"@project-serum/anchor"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmodule"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("exports")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("provider")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n anchor"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("setProvider")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("provider"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Add your deploy script here.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Migrations are a new feature\nand only support this simple deploy script at the moment.")]),t._v(" "),e("h2",{attrs:{id:"new"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#new"}},[t._v("#")]),t._v(" New")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor new \n")])])]),e("p",[t._v("Creates a new program in the workspace's "),e("code",[t._v("programs/")]),t._v(" directory initialized with boilerplate.")]),t._v(" "),e("h2",{attrs:{id:"test"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#test"}},[t._v("#")]),t._v(" Test")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor test\n")])])]),e("p",[t._v("Run an integration test suit against the configured cluster, deploying new versions\nof all workspace programs before running them.")]),t._v(" "),e("p",[t._v("If the configured network is a localnet, then automatically starts the localnetwork and runs\nthe test.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("Be sure to shutdown any other local validators, otherwise "),e("code",[t._v("anchor test")]),t._v(" will fail to run.")]),t._v(" "),e("p",[t._v("If you'd prefer to run the program against your local validator use "),e("code",[t._v("anchor test --skip-local-validator")]),t._v(".")])]),t._v(" "),e("p",[t._v("When running tests we stream program logs to "),e("code",[t._v(".anchor/program-logs/
..log")])]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("The Anchor workflow "),e("a",{attrs:{href:"https://www.parity.io/paritys-checklist-for-secure-smart-contract-development/",target:"_blank",rel:"noopener noreferrer"}},[t._v("recommends"),e("OutboundLink")],1),t._v("\nto test your program using integration tests in a language other\nthan Rust to make sure that bugs related to syntax misunderstandings\nare coverable with tests and not just replicated in tests.")])]),t._v(" "),e("h2",{attrs:{id:"upgrade"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#upgrade"}},[t._v("#")]),t._v(" Upgrade")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor upgrade --program-id \n")])])]),e("p",[t._v("Uses Solana's upgradeable BPF loader to upgrade the on chain program code.")]),t._v(" "),e("h2",{attrs:{id:"verify"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#verify"}},[t._v("#")]),t._v(" Verify")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor verify \n")])])]),e("p",[t._v("Verifies the on-chain bytecode matches the locally compiled artifact.")])])}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[10],{403:function(t,a,e){"use strict";e.r(a);var s=e(29),r=Object(s.a)({},(function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"commands"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#commands"}},[t._v("#")]),t._v(" Commands")]),t._v(" "),e("p",[t._v("A CLI is provided to support building and managing an Anchor workspace.\nFor a comprehensive list of commands and options, run "),e("code",[t._v("anchor -h")]),t._v(" on any\nof the following subcommands.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor-cli\n\nUSAGE:\n anchor \n\nFLAGS:\n -h, --help Prints help information\n -V, --version Prints version information\n\nSUBCOMMANDS:\n build Builds the workspace\n cluster Cluster commands\n deploy Deploys each program in the workspace\n expand Expands the macros of a program or the workspace\n help Prints this message or the help of the given subcommand(s)\n idl Commands for interacting with interface definitions\n init Initializes a workspace\n migrate Runs the deploy migration script\n new Creates a new program\n test Runs integration tests against a localnetwork\n upgrade Upgrades a single program. The configured wallet must be the upgrade authority\n verify Verifies the on-chain bytecode matches the locally compiled artifact. Run this\n command inside a program subdirectory, i.e., in the dir containing the program's\n Cargo.toml\n")])])]),e("h2",{attrs:{id:"build"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#build"}},[t._v("#")]),t._v(" Build")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor build\n")])])]),e("p",[t._v("Builds programs in the workspace targeting Solana's BPF runtime and emitting IDLs in the "),e("code",[t._v("target/idl")]),t._v(" directory.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor build --verifiable\n")])])]),e("p",[t._v("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, "),e("code",[t._v("programs//")]),t._v(".")]),t._v(" "),e("h2",{attrs:{id:"cluster"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cluster"}},[t._v("#")]),t._v(" Cluster")]),t._v(" "),e("h3",{attrs:{id:"cluster-list"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#cluster-list"}},[t._v("#")]),t._v(" Cluster list")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor cluster list\n")])])]),e("p",[t._v("This lists cluster endpoints:")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("Cluster Endpoints:\n\n* Mainnet - https://solana-api.projectserum.com\n* Mainnet - https://api.mainnet-beta.solana.com\n* Devnet - https://api.devnet.solana.com\n* Testnet - https://api.testnet.solana.com\n")])])]),e("h2",{attrs:{id:"deploy"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#deploy"}},[t._v("#")]),t._v(" Deploy")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor deploy\n")])])]),e("p",[t._v("Deploys all programs in the workspace to the configured cluster.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("This is different from the "),e("code",[t._v("solana program deploy")]),t._v(" command, because everytime it's run\nit will generate a "),e("em",[t._v("new")]),t._v(" program address.")])]),t._v(" "),e("h2",{attrs:{id:"expand"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#expand"}},[t._v("#")]),t._v(" Expand")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor expand\n")])])]),e("p",[t._v("If run inside a program folder, expands the macros of the program.")]),t._v(" "),e("p",[t._v("If run in the workspace but outside a program folder, expands the macros of the workspace.")]),t._v(" "),e("p",[t._v("If run with the "),e("code",[t._v("--program-name")]),t._v(" option, expand only the given program.")]),t._v(" "),e("h2",{attrs:{id:"idl"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl"}},[t._v("#")]),t._v(" Idl")]),t._v(" "),e("p",[t._v("The "),e("code",[t._v("idl")]),t._v(" subcommand provides commands for interacting with interface definition files.\nIt's recommended to use these commands to store an IDL on chain, at a deterministic\naddress, as a function of nothing but the the program's ID. This\nallows us to generate clients for a program using nothing but the program ID.")]),t._v(" "),e("h3",{attrs:{id:"idl-init"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-init"}},[t._v("#")]),t._v(" Idl Init")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl init -f \n")])])]),e("p",[t._v("Creates an idl account, writing the given "),e("code",[t._v("")]),t._v(" file into a program owned account. By default, the size of the account is double the size of the IDL,\nallowing room for growth in case the idl needs to be upgraded in the future.")]),t._v(" "),e("h3",{attrs:{id:"idl-fetch"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-fetch"}},[t._v("#")]),t._v(" Idl Fetch")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl fetch -o \n")])])]),e("p",[t._v("Fetches an IDL from the configured blockchain. For example, make sure\nyour "),e("code",[t._v("Anchor.toml")]),t._v(" is pointing to the "),e("code",[t._v("mainnet")]),t._v(" cluster and run")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl fetch GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv\n")])])]),e("h3",{attrs:{id:"idl-authority"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-authority"}},[t._v("#")]),t._v(" Idl Authority")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl authority \n")])])]),e("p",[t._v("Outputs the IDL account's authority. This is the wallet that has the ability to\nupdate the IDL.")]),t._v(" "),e("h3",{attrs:{id:"idl-erase-authority"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-erase-authority"}},[t._v("#")]),t._v(" Idl Erase Authority")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl erase-authority -p \n")])])]),e("p",[t._v("Erases the IDL account's authority so that upgrades can no longer occur. The\nconfigured wallet must be the current authority.")]),t._v(" "),e("h3",{attrs:{id:"idl-upgrade"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#idl-upgrade"}},[t._v("#")]),t._v(" Idl Upgrade")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl upgrade -f \n")])])]),e("p",[t._v("Upgrades the IDL file on chain to the new "),e("code",[t._v("target/idl/program.json")]),t._v(" idl.\nThe configured wallet must be the current authority.")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor idl set-authority -n -p \n")])])]),e("p",[t._v("Sets a new authority on the IDL account. Both the "),e("code",[t._v("new-authority")]),t._v(" and "),e("code",[t._v("program-id")]),t._v("\nmust be encoded in base 58.")]),t._v(" "),e("h2",{attrs:{id:"init"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#init"}},[t._v("#")]),t._v(" Init")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor init\n")])])]),e("p",[t._v("Initializes a project workspace with the following structure.")]),t._v(" "),e("ul",[e("li",[e("code",[t._v("Anchor.toml")]),t._v(": Anchor configuration file.")]),t._v(" "),e("li",[e("code",[t._v("Cargo.toml")]),t._v(": Rust workspace configuration file.")]),t._v(" "),e("li",[e("code",[t._v("package.json")]),t._v(": JavaScript dependencies file.")]),t._v(" "),e("li",[e("code",[t._v("programs/")]),t._v(": Directory for Solana program crates.")]),t._v(" "),e("li",[e("code",[t._v("app/")]),t._v(": Directory for your application frontend.")]),t._v(" "),e("li",[e("code",[t._v("tests/")]),t._v(": Directory for JavaScript integration tests.")]),t._v(" "),e("li",[e("code",[t._v("migrations/deploy.js")]),t._v(": Deploy script.")])]),t._v(" "),e("h2",{attrs:{id:"migrate"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#migrate"}},[t._v("#")]),t._v(" Migrate")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor migrate\n")])])]),e("p",[t._v("Runs the deploy script located at "),e("code",[t._v("migrations/deploy.js")]),t._v(", injecting a provider configured\nfrom the workspace's "),e("code",[t._v("Anchor.toml")]),t._v(". For example,")]),t._v(" "),e("div",{staticClass:"language-javascript extra-class"},[e("pre",{pre:!0,attrs:{class:"language-javascript"}},[e("code",[e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// File: migrations/deploys.js")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" anchor "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("require")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"@project-serum/anchor"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\nmodule"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function-variable function"}},[t._v("exports")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("async")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("function")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token parameter"}},[t._v("provider")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n anchor"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("setProvider")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("provider"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Add your deploy script here.")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Migrations are a new feature\nand only support this simple deploy script at the moment.")]),t._v(" "),e("h2",{attrs:{id:"new"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#new"}},[t._v("#")]),t._v(" New")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor new \n")])])]),e("p",[t._v("Creates a new program in the workspace's "),e("code",[t._v("programs/")]),t._v(" directory initialized with boilerplate.")]),t._v(" "),e("h2",{attrs:{id:"test"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#test"}},[t._v("#")]),t._v(" Test")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor test\n")])])]),e("p",[t._v("Run an integration test suit against the configured cluster, deploying new versions\nof all workspace programs before running them.")]),t._v(" "),e("p",[t._v("If the configured network is a localnet, then automatically starts the localnetwork and runs\nthe test.")]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("Be sure to shutdown any other local validators, otherwise "),e("code",[t._v("anchor test")]),t._v(" will fail to run.")]),t._v(" "),e("p",[t._v("If you'd prefer to run the program against your local validator use "),e("code",[t._v("anchor test --skip-local-validator")]),t._v(".")])]),t._v(" "),e("p",[t._v("When running tests we stream program logs to "),e("code",[t._v(".anchor/program-logs/
..log")])]),t._v(" "),e("div",{staticClass:"custom-block tip"},[e("p",{staticClass:"custom-block-title"},[t._v("Note")]),t._v(" "),e("p",[t._v("The Anchor workflow "),e("a",{attrs:{href:"https://www.parity.io/paritys-checklist-for-secure-smart-contract-development/",target:"_blank",rel:"noopener noreferrer"}},[t._v("recommends"),e("OutboundLink")],1),t._v("\nto test your program using integration tests in a language other\nthan Rust to make sure that bugs related to syntax misunderstandings\nare coverable with tests and not just replicated in tests.")])]),t._v(" "),e("h2",{attrs:{id:"upgrade"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#upgrade"}},[t._v("#")]),t._v(" Upgrade")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor upgrade --program-id \n")])])]),e("p",[t._v("Uses Solana's upgradeable BPF loader to upgrade the on chain program code.")]),t._v(" "),e("h2",{attrs:{id:"verify"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#verify"}},[t._v("#")]),t._v(" Verify")]),t._v(" "),e("div",{staticClass:"language- extra-class"},[e("pre",{pre:!0,attrs:{class:"language-text"}},[e("code",[t._v("anchor verify \n")])])]),e("p",[t._v("Verifies the on-chain bytecode matches the locally compiled artifact.")])])}),[],!1,null,null,null);a.default=r.exports}}]); \ No newline at end of file diff --git a/assets/js/11.0f0c790b.js b/assets/js/11.45e25cc5.js similarity index 98% rename from assets/js/11.0f0c790b.js rename to assets/js/11.45e25cc5.js index 5c672af1..c8a2a57e 100644 --- a/assets/js/11.0f0c790b.js +++ b/assets/js/11.45e25cc5.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{403:function(a,t,s){"use strict";s.r(t);var e=s(29),n=Object(e.a)({},(function(){var a=this,t=a.$createElement,s=a._self._c||t;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h1",{attrs:{id:"installing-dependencies"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#installing-dependencies"}},[a._v("#")]),a._v(" Installing Dependencies")]),a._v(" "),s("p",[a._v("To get started, make sure to setup all the prerequisite tools on your local machine\n(an installer has not yet been developed).")]),a._v(" "),s("h2",{attrs:{id:"install-rust"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-rust"}},[a._v("#")]),a._v(" Install Rust")]),a._v(" "),s("p",[a._v("For an introduction to Rust, see the excellent Rust "),s("a",{attrs:{href:"https://doc.rust-lang.org/book/",target:"_blank",rel:"noopener noreferrer"}},[a._v("book"),s("OutboundLink")],1),a._v(".")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("curl")]),a._v(" --proto "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v("'=https'")]),a._v(" --tlsv1.2 -sSf https://sh.rustup.rs "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("source")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("$HOME")]),a._v("/.cargo/env\nrustup component "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("add")]),a._v(" rustfmt\n")])])]),s("h2",{attrs:{id:"install-solana"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-solana"}},[a._v("#")]),a._v(" Install Solana")]),a._v(" "),s("p",[a._v("See the solana "),s("a",{attrs:{href:"https://docs.solana.com/cli/install-solana-cli-tools",target:"_blank",rel:"noopener noreferrer"}},[a._v("docs"),s("OutboundLink")],1),a._v(" for installation instructions. On macOS and Linux,")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),a._v(" -c "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),s("span",{pre:!0,attrs:{class:"token variable"}},[s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$(")]),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("curl")]),a._v(" -sSfL https://release.solana.com/v1.9.1/install"),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v(")")])]),a._v('"')]),a._v("\n")])])]),s("h2",{attrs:{id:"install-yarn"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-yarn"}},[a._v("#")]),a._v(" Install Yarn")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://yarnpkg.com/",target:"_blank",rel:"noopener noreferrer"}},[a._v("Yarn"),s("OutboundLink")],1),a._v(" is recommended for JavaScript package management.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("npm")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" -g "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("yarn")]),a._v("\n")])])]),s("h2",{attrs:{id:"install-anchor"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-anchor"}},[a._v("#")]),a._v(" Install Anchor")]),a._v(" "),s("h3",{attrs:{id:"install-using-pre-build-binary-on-x86-64-linux"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-using-pre-build-binary-on-x86-64-linux"}},[a._v("#")]),a._v(" Install using pre-build binary on x86_64 Linux")]),a._v(" "),s("p",[a._v("Anchor binaries are available via an NPM package "),s("a",{attrs:{href:"https://www.npmjs.com/package/@project-serum/anchor-cli",target:"_blank",rel:"noopener noreferrer"}},[s("code",[a._v("@project-serum/anchor-cli")]),s("OutboundLink")],1),a._v(". Only x86_64 Linux is supported currently, you must build from source for other OS'.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("npm")]),a._v(" i -g @project-serum/anchor-cli\n")])])]),s("h3",{attrs:{id:"build-from-source-for-other-operating-systems"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#build-from-source-for-other-operating-systems"}},[a._v("#")]),a._v(" Build from source for other operating systems")]),a._v(" "),s("p",[a._v("For now, we can use Cargo to install the CLI.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("cargo "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" --git https://github.com/project-serum/anchor --tag v0.24.1 anchor-cli --locked\n")])])]),s("p",[a._v("On Linux systems you may need to install additional dependencies if "),s("code",[a._v("cargo install")]),a._v(" fails. On Ubuntu,")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" update "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("&&")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" upgrade "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("&&")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" -y pkg-config build-essential libudev-dev\n")])])]),s("p",[a._v("Now verify the CLI is installed properly.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("anchor --version\n")])])]),s("h2",{attrs:{id:"start-a-project"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#start-a-project"}},[a._v("#")]),a._v(" Start a Project")]),a._v(" "),s("p",[a._v("To initialize a new project, simply run:")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("anchor init "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("new-project-name"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\n")])])]),s("h2",{attrs:{id:"minimum-version-requirements"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#minimum-version-requirements"}},[a._v("#")]),a._v(" Minimum version requirements")]),a._v(" "),s("table",[s("thead",[s("tr",[s("th",{staticStyle:{"text-align":"left"}},[a._v("Build tool")]),a._v(" "),s("th",{staticStyle:{"text-align":"left"}},[a._v("Version")])])]),a._v(" "),s("tbody",[s("tr",[s("td",{staticStyle:{"text-align":"left"}},[a._v("Node.js")]),a._v(" "),s("td",{staticStyle:{"text-align":"left"}},[a._v("v11.0.0")])])])])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{404:function(a,t,s){"use strict";s.r(t);var e=s(29),n=Object(e.a)({},(function(){var a=this,t=a.$createElement,s=a._self._c||t;return s("ContentSlotsDistributor",{attrs:{"slot-key":a.$parent.slotKey}},[s("h1",{attrs:{id:"installing-dependencies"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#installing-dependencies"}},[a._v("#")]),a._v(" Installing Dependencies")]),a._v(" "),s("p",[a._v("To get started, make sure to setup all the prerequisite tools on your local machine\n(an installer has not yet been developed).")]),a._v(" "),s("h2",{attrs:{id:"install-rust"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-rust"}},[a._v("#")]),a._v(" Install Rust")]),a._v(" "),s("p",[a._v("For an introduction to Rust, see the excellent Rust "),s("a",{attrs:{href:"https://doc.rust-lang.org/book/",target:"_blank",rel:"noopener noreferrer"}},[a._v("book"),s("OutboundLink")],1),a._v(".")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("curl")]),a._v(" --proto "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v("'=https'")]),a._v(" --tlsv1.2 -sSf https://sh.rustup.rs "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("|")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),a._v("\n"),s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[a._v("source")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token environment constant"}},[a._v("$HOME")]),a._v("/.cargo/env\nrustup component "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("add")]),a._v(" rustfmt\n")])])]),s("h2",{attrs:{id:"install-solana"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-solana"}},[a._v("#")]),a._v(" Install Solana")]),a._v(" "),s("p",[a._v("See the solana "),s("a",{attrs:{href:"https://docs.solana.com/cli/install-solana-cli-tools",target:"_blank",rel:"noopener noreferrer"}},[a._v("docs"),s("OutboundLink")],1),a._v(" for installation instructions. On macOS and Linux,")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sh")]),a._v(" -c "),s("span",{pre:!0,attrs:{class:"token string"}},[a._v('"'),s("span",{pre:!0,attrs:{class:"token variable"}},[s("span",{pre:!0,attrs:{class:"token variable"}},[a._v("$(")]),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("curl")]),a._v(" -sSfL https://release.solana.com/v1.9.1/install"),s("span",{pre:!0,attrs:{class:"token variable"}},[a._v(")")])]),a._v('"')]),a._v("\n")])])]),s("h2",{attrs:{id:"install-yarn"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-yarn"}},[a._v("#")]),a._v(" Install Yarn")]),a._v(" "),s("p",[s("a",{attrs:{href:"https://yarnpkg.com/",target:"_blank",rel:"noopener noreferrer"}},[a._v("Yarn"),s("OutboundLink")],1),a._v(" is recommended for JavaScript package management.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("npm")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" -g "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("yarn")]),a._v("\n")])])]),s("h2",{attrs:{id:"install-anchor"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-anchor"}},[a._v("#")]),a._v(" Install Anchor")]),a._v(" "),s("h3",{attrs:{id:"install-using-pre-build-binary-on-x86-64-linux"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#install-using-pre-build-binary-on-x86-64-linux"}},[a._v("#")]),a._v(" Install using pre-build binary on x86_64 Linux")]),a._v(" "),s("p",[a._v("Anchor binaries are available via an NPM package "),s("a",{attrs:{href:"https://www.npmjs.com/package/@project-serum/anchor-cli",target:"_blank",rel:"noopener noreferrer"}},[s("code",[a._v("@project-serum/anchor-cli")]),s("OutboundLink")],1),a._v(". Only x86_64 Linux is supported currently, you must build from source for other OS'.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("npm")]),a._v(" i -g @project-serum/anchor-cli\n")])])]),s("h3",{attrs:{id:"build-from-source-for-other-operating-systems"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#build-from-source-for-other-operating-systems"}},[a._v("#")]),a._v(" Build from source for other operating systems")]),a._v(" "),s("p",[a._v("For now, we can use Cargo to install the CLI.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("cargo "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" --git https://github.com/project-serum/anchor --tag v0.24.2 anchor-cli --locked\n")])])]),s("p",[a._v("On Linux systems you may need to install additional dependencies if "),s("code",[a._v("cargo install")]),a._v(" fails. On Ubuntu,")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" update "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("&&")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" upgrade "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("&&")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("sudo")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("apt-get")]),a._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[a._v("install")]),a._v(" -y pkg-config build-essential libudev-dev\n")])])]),s("p",[a._v("Now verify the CLI is installed properly.")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("anchor --version\n")])])]),s("h2",{attrs:{id:"start-a-project"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#start-a-project"}},[a._v("#")]),a._v(" Start a Project")]),a._v(" "),s("p",[a._v("To initialize a new project, simply run:")]),a._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[a._v("anchor init "),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v("<")]),a._v("new-project-name"),s("span",{pre:!0,attrs:{class:"token operator"}},[a._v(">")]),a._v("\n")])])]),s("h2",{attrs:{id:"minimum-version-requirements"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#minimum-version-requirements"}},[a._v("#")]),a._v(" Minimum version requirements")]),a._v(" "),s("table",[s("thead",[s("tr",[s("th",{staticStyle:{"text-align":"left"}},[a._v("Build tool")]),a._v(" "),s("th",{staticStyle:{"text-align":"left"}},[a._v("Version")])])]),a._v(" "),s("tbody",[s("tr",[s("td",{staticStyle:{"text-align":"left"}},[a._v("Node.js")]),a._v(" "),s("td",{staticStyle:{"text-align":"left"}},[a._v("v11.0.0")])])])])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/12.2382ff5e.js b/assets/js/12.d30544e0.js similarity index 97% rename from assets/js/12.2382ff5e.js rename to assets/js/12.d30544e0.js index fb9a1aee..38bd7adb 100644 --- a/assets/js/12.2382ff5e.js +++ b/assets/js/12.d30544e0.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{404:function(e,t,r){"use strict";r.r(t);var o=r(29),n=Object(o.a)({},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[r("h1",{attrs:{id:"introduction"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#introduction"}},[e._v("#")]),e._v(" Introduction")]),e._v(" "),r("div",{staticStyle:{border:"2px solid red","text-align":"center",padding:"10px 10px 10px 10px","box-sizing":"border-box"}},[e._v(" This documentation is being sunset in favor of "),r("a",{attrs:{href:"https://book.anchor-lang.com",rel:"noopener noreferrer",target:"_blank"}},[e._v("The Anchor Book")]),e._v(". At this point in time, either documentation may contain information that the other does not.")]),e._v(" "),r("p",[e._v("Anchor is a framework for Solana's "),r("a",{attrs:{href:"https://medium.com/solana-labs/sealevel-parallel-processing-thousands-of-smart-contracts-d814b378192",target:"_blank",rel:"noopener noreferrer"}},[e._v("Sealevel"),r("OutboundLink")],1),e._v(" runtime providing several convenient developer tools.")]),e._v(" "),r("ul",[r("li",[e._v("Rust crates and eDSL for writing Solana programs")]),e._v(" "),r("li",[r("a",{attrs:{href:"https://en.wikipedia.org/wiki/Interface_description_language",target:"_blank",rel:"noopener noreferrer"}},[e._v("IDL"),r("OutboundLink")],1),e._v(" specification")]),e._v(" "),r("li",[e._v("TypeScript package for generating clients from IDL")]),e._v(" "),r("li",[e._v("CLI and workspace management for developing complete applications")])]),e._v(" "),r("p",[e._v("If you're familiar with developing in Ethereum's "),r("a",{attrs:{href:"https://docs.soliditylang.org/en/v0.7.4/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Solidity"),r("OutboundLink")],1),e._v(", "),r("a",{attrs:{href:"https://www.trufflesuite.com/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Truffle"),r("OutboundLink")],1),e._v(", "),r("a",{attrs:{href:"https://github.com/ethereum/web3.js",target:"_blank",rel:"noopener noreferrer"}},[e._v("web3.js"),r("OutboundLink")],1),e._v(" or Parity's "),r("a",{attrs:{href:"https://github.com/paritytech/ink",target:"_blank",rel:"noopener noreferrer"}},[e._v("Ink!"),r("OutboundLink")],1),e._v(", then the experience will be familiar. Although the DSL syntax and semantics are targeted at Solana, the high level flow of writing RPC request handlers, emitting an IDL, and generating clients from IDL is the same.")]),e._v(" "),r("p",[e._v("Here, we'll walk through several tutorials demonstrating how to use Anchor. To skip the tutorials and jump straight to examples, go "),r("a",{attrs:{href:"https://github.com/project-serum/anchor/blob/master/examples",target:"_blank",rel:"noopener noreferrer"}},[e._v("here"),r("OutboundLink")],1),e._v(". For an introduction to Solana, see the "),r("a",{attrs:{href:"https://docs.solana.com/developing/programming-model/overview",target:"_blank",rel:"noopener noreferrer"}},[e._v("docs"),r("OutboundLink")],1),e._v(".")]),e._v(" "),r("div",{staticClass:"custom-block tip"},[r("p",{staticClass:"custom-block-title"},[e._v("NOTE")]),e._v(" "),r("p",[e._v("Anchor is in active development, so all APIs are subject to change. If you are one of the early developers to try it out and have feedback, please reach out by "),r("a",{attrs:{href:"https://github.com/project-serum/anchor/issues/new",target:"_blank",rel:"noopener noreferrer"}},[e._v("filing an issue"),r("OutboundLink")],1),e._v(". This documentation is a work in progress and is expected to change dramatically as features continue to be built out. If you have any problems, consult the "),r("a",{attrs:{href:"https://github.com/project-serum/anchor",target:"_blank",rel:"noopener noreferrer"}},[e._v("source"),r("OutboundLink")],1),e._v(" or feel free to ask questions on the "),r("a",{attrs:{href:"https://discord.gg/JgVgQ82erk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Discord"),r("OutboundLink")],1),e._v(".")])])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{405:function(e,t,r){"use strict";r.r(t);var o=r(29),n=Object(o.a)({},(function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[r("h1",{attrs:{id:"introduction"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#introduction"}},[e._v("#")]),e._v(" Introduction")]),e._v(" "),r("div",{staticStyle:{border:"2px solid red","text-align":"center",padding:"10px 10px 10px 10px","box-sizing":"border-box"}},[e._v(" This documentation is being sunset in favor of "),r("a",{attrs:{href:"https://book.anchor-lang.com",rel:"noopener noreferrer",target:"_blank"}},[e._v("The Anchor Book")]),e._v(". At this point in time, either documentation may contain information that the other does not.")]),e._v(" "),r("p",[e._v("Anchor is a framework for Solana's "),r("a",{attrs:{href:"https://medium.com/solana-labs/sealevel-parallel-processing-thousands-of-smart-contracts-d814b378192",target:"_blank",rel:"noopener noreferrer"}},[e._v("Sealevel"),r("OutboundLink")],1),e._v(" runtime providing several convenient developer tools.")]),e._v(" "),r("ul",[r("li",[e._v("Rust crates and eDSL for writing Solana programs")]),e._v(" "),r("li",[r("a",{attrs:{href:"https://en.wikipedia.org/wiki/Interface_description_language",target:"_blank",rel:"noopener noreferrer"}},[e._v("IDL"),r("OutboundLink")],1),e._v(" specification")]),e._v(" "),r("li",[e._v("TypeScript package for generating clients from IDL")]),e._v(" "),r("li",[e._v("CLI and workspace management for developing complete applications")])]),e._v(" "),r("p",[e._v("If you're familiar with developing in Ethereum's "),r("a",{attrs:{href:"https://docs.soliditylang.org/en/v0.7.4/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Solidity"),r("OutboundLink")],1),e._v(", "),r("a",{attrs:{href:"https://www.trufflesuite.com/",target:"_blank",rel:"noopener noreferrer"}},[e._v("Truffle"),r("OutboundLink")],1),e._v(", "),r("a",{attrs:{href:"https://github.com/ethereum/web3.js",target:"_blank",rel:"noopener noreferrer"}},[e._v("web3.js"),r("OutboundLink")],1),e._v(" or Parity's "),r("a",{attrs:{href:"https://github.com/paritytech/ink",target:"_blank",rel:"noopener noreferrer"}},[e._v("Ink!"),r("OutboundLink")],1),e._v(", then the experience will be familiar. Although the DSL syntax and semantics are targeted at Solana, the high level flow of writing RPC request handlers, emitting an IDL, and generating clients from IDL is the same.")]),e._v(" "),r("p",[e._v("Here, we'll walk through several tutorials demonstrating how to use Anchor. To skip the tutorials and jump straight to examples, go "),r("a",{attrs:{href:"https://github.com/project-serum/anchor/blob/master/examples",target:"_blank",rel:"noopener noreferrer"}},[e._v("here"),r("OutboundLink")],1),e._v(". For an introduction to Solana, see the "),r("a",{attrs:{href:"https://docs.solana.com/developing/programming-model/overview",target:"_blank",rel:"noopener noreferrer"}},[e._v("docs"),r("OutboundLink")],1),e._v(".")]),e._v(" "),r("div",{staticClass:"custom-block tip"},[r("p",{staticClass:"custom-block-title"},[e._v("NOTE")]),e._v(" "),r("p",[e._v("Anchor is in active development, so all APIs are subject to change. If you are one of the early developers to try it out and have feedback, please reach out by "),r("a",{attrs:{href:"https://github.com/project-serum/anchor/issues/new",target:"_blank",rel:"noopener noreferrer"}},[e._v("filing an issue"),r("OutboundLink")],1),e._v(". This documentation is a work in progress and is expected to change dramatically as features continue to be built out. If you have any problems, consult the "),r("a",{attrs:{href:"https://github.com/project-serum/anchor",target:"_blank",rel:"noopener noreferrer"}},[e._v("source"),r("OutboundLink")],1),e._v(" or feel free to ask questions on the "),r("a",{attrs:{href:"https://discord.gg/JgVgQ82erk",target:"_blank",rel:"noopener noreferrer"}},[e._v("Discord"),r("OutboundLink")],1),e._v(".")])])])}),[],!1,null,null,null);t.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/13.c7c68919.js b/assets/js/13.7bb3490d.js similarity index 97% rename from assets/js/13.c7c68919.js rename to assets/js/13.7bb3490d.js index 842c8f82..d3cefe58 100644 --- a/assets/js/13.c7c68919.js +++ b/assets/js/13.7bb3490d.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[13],{405:function(r,e,t){"use strict";t.r(e);var o=t(29),n=Object(o.a)({},(function(){var r=this,e=r.$createElement,t=r._self._c||e;return t("ContentSlotsDistributor",{attrs:{"slot-key":r.$parent.slotKey}},[t("h1",{attrs:{id:"projects"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#projects"}},[r._v("#")]),r._v(" Projects")]),r._v(" "),t("p",[r._v("Open a pull request to add your project to the "),t("a",{attrs:{href:"https://github.com/project-serum/anchor/blob/master/docs/src/getting-started/projects.md",target:"_blank",rel:"noopener noreferrer"}},[r._v("list"),t("OutboundLink")],1),r._v(".")]),r._v(" "),t("ul",[t("li",[t("a",{attrs:{href:"https://github.com/project-serum",target:"_blank",rel:"noopener noreferrer"}},[r._v("Serum"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://github.com/Synthetify",target:"_blank",rel:"noopener noreferrer"}},[r._v("Synthetify"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://solfarm.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("SolFarm"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://zeta.markets/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Zeta Markets"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://saber.so",target:"_blank",rel:"noopener noreferrer"}},[r._v("Saber"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://01protocol.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("01"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://parrot.fi/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Parrot Finance"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://marinade.finance/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Marinade Finance"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://dex.aldrin.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Aldrin"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://cyclos.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Cyclos"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://solend.fi",target:"_blank",rel:"noopener noreferrer"}},[r._v("Solend"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://www.drift.trade/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Drift"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://stake.fsynth.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Fabric"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://jetprotocol.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Jet Protocol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://quarry.so/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Quarry"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://psyoptions.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("PsyOptions"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://sosol.app/",target:"_blank",rel:"noopener noreferrer"}},[r._v("sosol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://arrowprotocol.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Arrow Protocol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://hubbleprotocol.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Hubble Protocol"),t("OutboundLink")],1)])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[13],{406:function(r,e,t){"use strict";t.r(e);var o=t(29),n=Object(o.a)({},(function(){var r=this,e=r.$createElement,t=r._self._c||e;return t("ContentSlotsDistributor",{attrs:{"slot-key":r.$parent.slotKey}},[t("h1",{attrs:{id:"projects"}},[t("a",{staticClass:"header-anchor",attrs:{href:"#projects"}},[r._v("#")]),r._v(" Projects")]),r._v(" "),t("p",[r._v("Open a pull request to add your project to the "),t("a",{attrs:{href:"https://github.com/project-serum/anchor/blob/master/docs/src/getting-started/projects.md",target:"_blank",rel:"noopener noreferrer"}},[r._v("list"),t("OutboundLink")],1),r._v(".")]),r._v(" "),t("ul",[t("li",[t("a",{attrs:{href:"https://github.com/project-serum",target:"_blank",rel:"noopener noreferrer"}},[r._v("Serum"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://github.com/Synthetify",target:"_blank",rel:"noopener noreferrer"}},[r._v("Synthetify"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://solfarm.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("SolFarm"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://zeta.markets/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Zeta Markets"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://saber.so",target:"_blank",rel:"noopener noreferrer"}},[r._v("Saber"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://01protocol.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("01"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://parrot.fi/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Parrot Finance"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://marinade.finance/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Marinade Finance"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://dex.aldrin.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Aldrin"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://cyclos.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Cyclos"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://solend.fi",target:"_blank",rel:"noopener noreferrer"}},[r._v("Solend"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://www.drift.trade/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Drift"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://stake.fsynth.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Fabric"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://jetprotocol.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Jet Protocol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://quarry.so/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Quarry"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://psyoptions.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("PsyOptions"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://sosol.app/",target:"_blank",rel:"noopener noreferrer"}},[r._v("sosol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://arrowprotocol.com/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Arrow Protocol"),t("OutboundLink")],1)]),r._v(" "),t("li",[t("a",{attrs:{href:"https://hubbleprotocol.io/",target:"_blank",rel:"noopener noreferrer"}},[r._v("Hubble Protocol"),t("OutboundLink")],1)])])])}),[],!1,null,null,null);e.default=n.exports}}]); \ No newline at end of file diff --git a/assets/js/14.b3c5cf32.js b/assets/js/14.258e35e3.js similarity index 97% rename from assets/js/14.b3c5cf32.js rename to assets/js/14.258e35e3.js index 6388a7ad..08fd883b 100644 --- a/assets/js/14.b3c5cf32.js +++ b/assets/js/14.258e35e3.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{409:function(t,e,a){"use strict";a.r(e);var r=a(29),s=Object(r.a)({},(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"publishing-source"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#publishing-source"}},[t._v("#")]),t._v(" Publishing Source")]),t._v(" "),a("p",[t._v("The Anchor Program Registry at "),a("a",{attrs:{href:"https://anchor.projectserum.com",target:"_blank",rel:"noopener noreferrer"}},[t._v("anchor.projectserum.com"),a("OutboundLink")],1),t._v("\nhosts a catalog of verified programs on Solana both written with and without Anchor. It is recommended\nthat authors of smart contracts publish their source to promote best\npractices for security and transparency.")]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",{staticClass:"custom-block-title"},[t._v("note")]),t._v(" "),a("p",[t._v("The Anchor Program Registry is currently in alpha testing. For access to publishing\nplease ask on "),a("a",{attrs:{href:"https://discord.gg/rg5ZZPmmTm",target:"_blank",rel:"noopener noreferrer"}},[t._v("Discord"),a("OutboundLink")],1),t._v(".")])]),t._v(" "),a("h2",{attrs:{id:"getting-started"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#getting-started"}},[t._v("#")]),t._v(" Getting Started")]),t._v(" "),a("p",[t._v("The process for publishing is mostly identical to "),a("code",[t._v("crates.io")]),t._v(".")]),t._v(" "),a("ul",[a("li",[t._v("Signup for an account "),a("a",{attrs:{href:"https://anchor.projectserum.com/signup",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("li",[t._v("Confirm your email by clicking the link sent to your address.")]),t._v(" "),a("li",[t._v("Navigate to your Username -> Account Settings on the top navbar.")]),t._v(" "),a("li",[t._v('Click "New Token" in the '),a("strong",[t._v("API Access")]),t._v(" section.")]),t._v(" "),a("li",[t._v("Run "),a("code",[t._v("anchor login ")]),t._v(" at the command line.")])]),t._v(" "),a("p",[t._v("And you're ready to interact with the registry.")]),t._v(" "),a("h2",{attrs:{id:"configuring-a-build"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-build"}},[t._v("#")]),t._v(" Configuring a Build")]),t._v(" "),a("p",[t._v("Whether your program is written in Anchor or not, all source being published must\nhave an "),a("code",[t._v("Anchor.toml")]),t._v(" to define the build.")]),t._v(" "),a("p",[t._v("An example "),a("code",[t._v("Anchor.toml")]),t._v(" config looks as follows,")]),t._v(" "),a("div",{staticClass:"language-toml extra-class"},[a("pre",{pre:!0,attrs:{class:"language-toml"}},[a("code",[a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("anchor_version")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"0.24.1"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("workspace")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("members")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"programs/multisig"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("provider")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("cluster")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"mainnet"')]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("wallet")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"~/.config/solana/id.json"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("programs.mainnet")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("multisig")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A9HAbnCwoD6f2NkZobKFf6buJoN9gUVVvX5PoUnDHS6u"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("programs.localnet")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("multisig")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A9HAbnCwoD6f2NkZobKFf6buJoN9gUVVvX5PoUnDHS6u"')]),t._v("\n")])])]),a("p",[t._v("Here there are four sections.")]),t._v(" "),a("ol",[a("li",[a("code",[t._v("anchor_version")]),t._v(" (optional) - sets the anchor docker image to use. By default, the builder will use the latest version of Anchor.")]),t._v(" "),a("li",[a("code",[t._v("[workspace]")]),t._v(" (optional) - sets the paths--relative to the "),a("code",[t._v("Anchor.toml")]),t._v("--\nto all programs in the local\nworkspace, i.e., the path to the "),a("code",[t._v("Cargo.toml")]),t._v(" manifest associated with each\nprogram that can be compiled by the "),a("code",[t._v("anchor")]),t._v(" CLI. For programs using the\nstandard Anchor workflow, this can be ommitted. For programs not written in Anchor\nbut still want to publish, this should be added.")]),t._v(" "),a("li",[a("code",[t._v("[provider]")]),t._v(" - configures the wallet and cluster settings. Here, "),a("code",[t._v("mainnet")]),t._v(" is used because the registry only supports "),a("code",[t._v("mainnet")]),t._v(" binary verification at the moment.")]),t._v(" "),a("li",[a("code",[t._v("[programs.mainnet]")]),t._v(" - configures each program in the workpace, providing\nthe "),a("code",[t._v("address")]),t._v(" of the program to verify.")])]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),a("p",[t._v("When defining program in "),a("code",[t._v("[programs.mainnet]")]),t._v(", make sure the name provided\nmatches the "),a("strong",[t._v("lib")]),t._v(" name for your program, which is defined\nby your program's Cargo.toml.")])]),t._v(" "),a("h3",{attrs:{id:"examples"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#examples"}},[t._v("#")]),t._v(" Examples")]),t._v(" "),a("h4",{attrs:{id:"anchor-program"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#anchor-program"}},[t._v("#")]),t._v(" Anchor Program")]),t._v(" "),a("p",[t._v("An example of a toml file for an Anchor program can be found "),a("a",{attrs:{href:"https://anchor.projectserum.com/build/2",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("h4",{attrs:{id:"non-anchor-program"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#non-anchor-program"}},[t._v("#")]),t._v(" Non Anchor Program")]),t._v(" "),a("p",[t._v("An example of a toml file for a non-anchor program can be found "),a("a",{attrs:{href:"https://anchor.projectserum.com/build/1",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("h2",{attrs:{id:"publishing"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#publishing"}},[t._v("#")]),t._v(" Publishing")]),t._v(" "),a("p",[t._v("To publish to the Anchor Program Registry, change directories to the "),a("code",[t._v("Anchor.toml")]),t._v("\ndefined root and run")]),t._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[t._v("anchor publish "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("program-name"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("where "),a("code",[t._v("")]),t._v(" is as defined in "),a("code",[t._v("[programs.mainnet]")]),t._v(", i.e., "),a("code",[t._v("multisig")]),t._v("\nin the example above.")])])}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[14],{408:function(t,e,a){"use strict";a.r(e);var r=a(29),s=Object(r.a)({},(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"publishing-source"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#publishing-source"}},[t._v("#")]),t._v(" Publishing Source")]),t._v(" "),a("p",[t._v("The Anchor Program Registry at "),a("a",{attrs:{href:"https://anchor.projectserum.com",target:"_blank",rel:"noopener noreferrer"}},[t._v("anchor.projectserum.com"),a("OutboundLink")],1),t._v("\nhosts a catalog of verified programs on Solana both written with and without Anchor. It is recommended\nthat authors of smart contracts publish their source to promote best\npractices for security and transparency.")]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",{staticClass:"custom-block-title"},[t._v("note")]),t._v(" "),a("p",[t._v("The Anchor Program Registry is currently in alpha testing. For access to publishing\nplease ask on "),a("a",{attrs:{href:"https://discord.gg/rg5ZZPmmTm",target:"_blank",rel:"noopener noreferrer"}},[t._v("Discord"),a("OutboundLink")],1),t._v(".")])]),t._v(" "),a("h2",{attrs:{id:"getting-started"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#getting-started"}},[t._v("#")]),t._v(" Getting Started")]),t._v(" "),a("p",[t._v("The process for publishing is mostly identical to "),a("code",[t._v("crates.io")]),t._v(".")]),t._v(" "),a("ul",[a("li",[t._v("Signup for an account "),a("a",{attrs:{href:"https://anchor.projectserum.com/signup",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("li",[t._v("Confirm your email by clicking the link sent to your address.")]),t._v(" "),a("li",[t._v("Navigate to your Username -> Account Settings on the top navbar.")]),t._v(" "),a("li",[t._v('Click "New Token" in the '),a("strong",[t._v("API Access")]),t._v(" section.")]),t._v(" "),a("li",[t._v("Run "),a("code",[t._v("anchor login ")]),t._v(" at the command line.")])]),t._v(" "),a("p",[t._v("And you're ready to interact with the registry.")]),t._v(" "),a("h2",{attrs:{id:"configuring-a-build"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#configuring-a-build"}},[t._v("#")]),t._v(" Configuring a Build")]),t._v(" "),a("p",[t._v("Whether your program is written in Anchor or not, all source being published must\nhave an "),a("code",[t._v("Anchor.toml")]),t._v(" to define the build.")]),t._v(" "),a("p",[t._v("An example "),a("code",[t._v("Anchor.toml")]),t._v(" config looks as follows,")]),t._v(" "),a("div",{staticClass:"language-toml extra-class"},[a("pre",{pre:!0,attrs:{class:"language-toml"}},[a("code",[a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("anchor_version")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"0.24.2"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("workspace")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("members")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"programs/multisig"')]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("provider")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("cluster")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"mainnet"')]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("wallet")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"~/.config/solana/id.json"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("programs.mainnet")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("multisig")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A9HAbnCwoD6f2NkZobKFf6buJoN9gUVVvX5PoUnDHS6u"')]),t._v("\n\n"),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),a("span",{pre:!0,attrs:{class:"token table class-name"}},[t._v("programs.localnet")]),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n"),a("span",{pre:!0,attrs:{class:"token key property"}},[t._v("multisig")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("=")]),t._v(" "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"A9HAbnCwoD6f2NkZobKFf6buJoN9gUVVvX5PoUnDHS6u"')]),t._v("\n")])])]),a("p",[t._v("Here there are four sections.")]),t._v(" "),a("ol",[a("li",[a("code",[t._v("anchor_version")]),t._v(" (optional) - sets the anchor docker image to use. By default, the builder will use the latest version of Anchor.")]),t._v(" "),a("li",[a("code",[t._v("[workspace]")]),t._v(" (optional) - sets the paths--relative to the "),a("code",[t._v("Anchor.toml")]),t._v("--\nto all programs in the local\nworkspace, i.e., the path to the "),a("code",[t._v("Cargo.toml")]),t._v(" manifest associated with each\nprogram that can be compiled by the "),a("code",[t._v("anchor")]),t._v(" CLI. For programs using the\nstandard Anchor workflow, this can be ommitted. For programs not written in Anchor\nbut still want to publish, this should be added.")]),t._v(" "),a("li",[a("code",[t._v("[provider]")]),t._v(" - configures the wallet and cluster settings. Here, "),a("code",[t._v("mainnet")]),t._v(" is used because the registry only supports "),a("code",[t._v("mainnet")]),t._v(" binary verification at the moment.")]),t._v(" "),a("li",[a("code",[t._v("[programs.mainnet]")]),t._v(" - configures each program in the workpace, providing\nthe "),a("code",[t._v("address")]),t._v(" of the program to verify.")])]),t._v(" "),a("div",{staticClass:"custom-block tip"},[a("p",{staticClass:"custom-block-title"},[t._v("TIP")]),t._v(" "),a("p",[t._v("When defining program in "),a("code",[t._v("[programs.mainnet]")]),t._v(", make sure the name provided\nmatches the "),a("strong",[t._v("lib")]),t._v(" name for your program, which is defined\nby your program's Cargo.toml.")])]),t._v(" "),a("h3",{attrs:{id:"examples"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#examples"}},[t._v("#")]),t._v(" Examples")]),t._v(" "),a("h4",{attrs:{id:"anchor-program"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#anchor-program"}},[t._v("#")]),t._v(" Anchor Program")]),t._v(" "),a("p",[t._v("An example of a toml file for an Anchor program can be found "),a("a",{attrs:{href:"https://anchor.projectserum.com/build/2",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("h4",{attrs:{id:"non-anchor-program"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#non-anchor-program"}},[t._v("#")]),t._v(" Non Anchor Program")]),t._v(" "),a("p",[t._v("An example of a toml file for a non-anchor program can be found "),a("a",{attrs:{href:"https://anchor.projectserum.com/build/1",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),a("OutboundLink")],1),t._v(".")]),t._v(" "),a("h2",{attrs:{id:"publishing"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#publishing"}},[t._v("#")]),t._v(" Publishing")]),t._v(" "),a("p",[t._v("To publish to the Anchor Program Registry, change directories to the "),a("code",[t._v("Anchor.toml")]),t._v("\ndefined root and run")]),t._v(" "),a("div",{staticClass:"language-bash extra-class"},[a("pre",{pre:!0,attrs:{class:"language-bash"}},[a("code",[t._v("anchor publish "),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),t._v("program-name"),a("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v("\n")])])]),a("p",[t._v("where "),a("code",[t._v("")]),t._v(" is as defined in "),a("code",[t._v("[programs.mainnet]")]),t._v(", i.e., "),a("code",[t._v("multisig")]),t._v("\nin the example above.")])])}),[],!1,null,null,null);e.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/15.0c123204.js b/assets/js/15.243176ff.js similarity index 96% rename from assets/js/15.0c123204.js rename to assets/js/15.243176ff.js index ada8eb60..369cec5e 100644 --- a/assets/js/15.0c123204.js +++ b/assets/js/15.243176ff.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{407:function(e,a,r){"use strict";r.r(a);var t=r(29),s=Object(t.a)({},(function(){var e=this,a=e.$createElement,r=e._self._c||a;return r("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[r("h1",{attrs:{id:"verifiable-builds"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#verifiable-builds"}},[e._v("#")]),e._v(" Verifiable Builds")]),e._v(" "),r("p",[e._v("Building programs with the Solana CLI may embed machine specfic\ncode into the resulting binary. As a result, building the same program\non different machines may produce different executables. To get around this\nproblem, one can build inside a docker image with pinned dependencies to produce\na verifiable build.")]),e._v(" "),r("p",[e._v("Anchor makes this easy by providing CLI commands to build and take care of\ndocker for you. To get started, first make sure you\n"),r("a",{attrs:{href:"https://docs.docker.com/get-docker/",target:"_blank",rel:"noopener noreferrer"}},[e._v("install"),r("OutboundLink")],1),e._v(" docker on your local machine.")]),e._v(" "),r("h2",{attrs:{id:"building"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#building"}},[e._v("#")]),e._v(" Building")]),e._v(" "),r("p",[e._v("To produce a verifiable build, run")]),e._v(" "),r("div",{staticClass:"language-bash extra-class"},[r("pre",{pre:!0,attrs:{class:"language-bash"}},[r("code",[e._v("anchor build --verifiable\n")])])]),r("h2",{attrs:{id:"verifying"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#verifying"}},[e._v("#")]),e._v(" Verifying")]),e._v(" "),r("p",[e._v("To verify a build against a program deployed on mainnet, run")]),e._v(" "),r("div",{staticClass:"language-bash extra-class"},[r("pre",{pre:!0,attrs:{class:"language-bash"}},[r("code",[e._v("anchor verify -p "),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("lib-name"),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v(" "),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("program-id"),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n")])])]),r("p",[e._v("where the "),r("code",[e._v("")]),e._v(" is defined by your program's Cargo.toml.")]),e._v(" "),r("p",[e._v("If the program has an IDL, it will also check the IDL deployed on chain matches.")]),e._v(" "),r("h2",{attrs:{id:"images"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#images"}},[e._v("#")]),e._v(" Images")]),e._v(" "),r("p",[e._v("A docker image for each version of Anchor is published on "),r("a",{attrs:{href:"https://hub.docker.com/r/projectserum/build",target:"_blank",rel:"noopener noreferrer"}},[e._v("Docker Hub"),r("OutboundLink")],1),e._v(". They are tagged in the form "),r("code",[e._v("projectserum/build:")]),e._v(". For example, to get the image for Anchor "),r("code",[e._v("v0.24.1")]),e._v(" one can run")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("docker pull projectserum/build:v0.24.1\n")])])]),r("h2",{attrs:{id:"removing-an-image"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#removing-an-image"}},[e._v("#")]),e._v(" Removing an Image")]),e._v(" "),r("p",[e._v("In the event you run a verifiable build from the CLI and exit prematurely,\nit's possible the docker image may still be building in the background.")]),e._v(" "),r("p",[e._v("To remove, run")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("docker rm -f anchor-program\n")])])]),r("p",[e._v("where "),r("code",[e._v("anchor-program")]),e._v(" is the name of the image created by default from within\nthe Anchor CLI.")])])}),[],!1,null,null,null);a.default=s.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[15],{407:function(e,a,r){"use strict";r.r(a);var t=r(29),s=Object(t.a)({},(function(){var e=this,a=e.$createElement,r=e._self._c||a;return r("ContentSlotsDistributor",{attrs:{"slot-key":e.$parent.slotKey}},[r("h1",{attrs:{id:"verifiable-builds"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#verifiable-builds"}},[e._v("#")]),e._v(" Verifiable Builds")]),e._v(" "),r("p",[e._v("Building programs with the Solana CLI may embed machine specfic\ncode into the resulting binary. As a result, building the same program\non different machines may produce different executables. To get around this\nproblem, one can build inside a docker image with pinned dependencies to produce\na verifiable build.")]),e._v(" "),r("p",[e._v("Anchor makes this easy by providing CLI commands to build and take care of\ndocker for you. To get started, first make sure you\n"),r("a",{attrs:{href:"https://docs.docker.com/get-docker/",target:"_blank",rel:"noopener noreferrer"}},[e._v("install"),r("OutboundLink")],1),e._v(" docker on your local machine.")]),e._v(" "),r("h2",{attrs:{id:"building"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#building"}},[e._v("#")]),e._v(" Building")]),e._v(" "),r("p",[e._v("To produce a verifiable build, run")]),e._v(" "),r("div",{staticClass:"language-bash extra-class"},[r("pre",{pre:!0,attrs:{class:"language-bash"}},[r("code",[e._v("anchor build --verifiable\n")])])]),r("h2",{attrs:{id:"verifying"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#verifying"}},[e._v("#")]),e._v(" Verifying")]),e._v(" "),r("p",[e._v("To verify a build against a program deployed on mainnet, run")]),e._v(" "),r("div",{staticClass:"language-bash extra-class"},[r("pre",{pre:!0,attrs:{class:"language-bash"}},[r("code",[e._v("anchor verify -p "),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("lib-name"),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v(" "),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v("<")]),e._v("program-id"),r("span",{pre:!0,attrs:{class:"token operator"}},[e._v(">")]),e._v("\n")])])]),r("p",[e._v("where the "),r("code",[e._v("")]),e._v(" is defined by your program's Cargo.toml.")]),e._v(" "),r("p",[e._v("If the program has an IDL, it will also check the IDL deployed on chain matches.")]),e._v(" "),r("h2",{attrs:{id:"images"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#images"}},[e._v("#")]),e._v(" Images")]),e._v(" "),r("p",[e._v("A docker image for each version of Anchor is published on "),r("a",{attrs:{href:"https://hub.docker.com/r/projectserum/build",target:"_blank",rel:"noopener noreferrer"}},[e._v("Docker Hub"),r("OutboundLink")],1),e._v(". They are tagged in the form "),r("code",[e._v("projectserum/build:")]),e._v(". For example, to get the image for Anchor "),r("code",[e._v("v0.24.2")]),e._v(" one can run")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("docker pull projectserum/build:v0.24.2\n")])])]),r("h2",{attrs:{id:"removing-an-image"}},[r("a",{staticClass:"header-anchor",attrs:{href:"#removing-an-image"}},[e._v("#")]),e._v(" Removing an Image")]),e._v(" "),r("p",[e._v("In the event you run a verifiable build from the CLI and exit prematurely,\nit's possible the docker image may still be building in the background.")]),e._v(" "),r("p",[e._v("To remove, run")]),e._v(" "),r("div",{staticClass:"language- extra-class"},[r("pre",{pre:!0,attrs:{class:"language-text"}},[r("code",[e._v("docker rm -f anchor-program\n")])])]),r("p",[e._v("where "),r("code",[e._v("anchor-program")]),e._v(" is the name of the image created by default from within\nthe Anchor CLI.")])])}),[],!1,null,null,null);a.default=s.exports}}]); \ No newline at end of file diff --git a/assets/js/16.1bba98d0.js b/assets/js/16.b6cb9e25.js similarity index 87% rename from assets/js/16.1bba98d0.js rename to assets/js/16.b6cb9e25.js index b2639e8f..9455c6c4 100644 --- a/assets/js/16.1bba98d0.js +++ b/assets/js/16.b6cb9e25.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[16],{408:function(t,e,n){"use strict";n.r(e);var o=n(29),i=Object(o.a)({},(function(){var t=this.$createElement,e=this._self._c||t;return e("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[e("div",{staticStyle:{border:"2px solid red","text-align":"center",padding:"10px 10px 10px 10px","box-sizing":"border-box"}},[this._v(" This documentation is being sunset in favor of "),e("a",{attrs:{href:"https://book.anchor-lang.com",rel:"noopener noreferrer",target:"_blank"}},[this._v("The Anchor Book")]),this._v(". At this point in time, either documentation may contain information that the other does not.")])])}),[],!1,null,null,null);e.default=i.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[16],{409:function(t,e,n){"use strict";n.r(e);var o=n(29),i=Object(o.a)({},(function(){var t=this.$createElement,e=this._self._c||t;return e("ContentSlotsDistributor",{attrs:{"slot-key":this.$parent.slotKey}},[e("div",{staticStyle:{border:"2px solid red","text-align":"center",padding:"10px 10px 10px 10px","box-sizing":"border-box"}},[this._v(" This documentation is being sunset in favor of "),e("a",{attrs:{href:"https://book.anchor-lang.com",rel:"noopener noreferrer",target:"_blank"}},[this._v("The Anchor Book")]),this._v(". At this point in time, either documentation may contain information that the other does not.")])])}),[],!1,null,null,null);e.default=i.exports}}]); \ No newline at end of file diff --git a/assets/js/18.a3c88079.js b/assets/js/18.db5dc2ee.js similarity index 99% rename from assets/js/18.a3c88079.js rename to assets/js/18.db5dc2ee.js index 2233c91b..c9b3ae55 100644 --- a/assets/js/18.a3c88079.js +++ b/assets/js/18.db5dc2ee.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[18],{412:function(t,a,s){"use strict";s.r(a);var n=s(29),e=Object(n.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"arguments-and-accounts"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#arguments-and-accounts"}},[t._v("#")]),t._v(" Arguments and Accounts")]),t._v(" "),s("p",[t._v("This tutorial covers the basics of creating and mutating accounts using Anchor.\nIt's recommended to read "),s("RouterLink",{attrs:{to:"/tutorials/tutorial-0.html"}},[t._v("Tutorial 0")]),t._v(" first, as this tutorial will\nbuild on top of it.")],1),t._v(" "),s("h2",{attrs:{id:"clone-the-repo"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#clone-the-repo"}},[t._v("#")]),t._v(" Clone the Repo")]),t._v(" "),s("p",[t._v("To get started, clone the repo.")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone https://github.com/project-serum/anchor\n")])])]),s("p",[t._v("Change directories to the "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-1",target:"_blank",rel:"noopener noreferrer"}},[t._v("example"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" anchor/examples/tutorial/basic-1\n")])])]),s("p",[t._v("And install any additional JavaScript dependencies:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("yarn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v("\n")])])]),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("We define our program as follows")]),t._v(" "),s("div",{staticClass:"language-rs extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rs"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("declare_id!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("basic_1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("initialize")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Initialize")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" my_account "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("update")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Update")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" my_account "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Initialize")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(init, payer = user, space = 8 + 8)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("MyAccount")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" system_program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Program")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("System")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Update")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("MyAccount")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("MyAccount")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Some new syntax elements are introduced here.")]),t._v(" "),s("h3",{attrs:{id:"initialize-instruction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#initialize-instruction"}},[t._v("#")]),t._v(" "),s("code",[t._v("initialize")]),t._v(" instruction")]),t._v(" "),s("p",[t._v("First, let's start with the initialize instruction. Notice the "),s("code",[t._v("data")]),t._v(" argument passed into the program. This argument and any other valid\nRust types can be passed to the instruction to define inputs to the program.")]),t._v(" "),s("p",[t._v("Additionally,\nnotice how we take a mutable reference to "),s("code",[t._v("my_account")]),t._v(" and assign the "),s("code",[t._v("data")]),t._v(" to it. This leads us to\nthe "),s("code",[t._v("Initialize")]),t._v(" struct, deriving "),s("code",[t._v("Accounts")]),t._v(". There are two things to notice about "),s("code",[t._v("Initialize")]),t._v(".")]),t._v(" "),s("ol",[s("li",[t._v("The "),s("code",[t._v("my_account")]),t._v(" field is of type "),s("code",[t._v("Account<'info, MyAccount>")]),t._v(" and the deserialized data structure is "),s("code",[t._v("MyAccount")]),t._v(".")]),t._v(" "),s("li",[t._v("The "),s("code",[t._v("my_account")]),t._v(" field is marked with the "),s("code",[t._v("init")]),t._v(" attribute. This will create a new\naccount owned by the current program, zero initialized. When using "),s("code",[t._v("init")]),t._v(", one must also provide\n"),s("code",[t._v("payer")]),t._v(", which will fund the account creation, "),s("code",[t._v("space")]),t._v(", which defines how large the account should be,\nand the "),s("code",[t._v("system_program")]),t._v(", which is required by the runtime for creating the account.")])]),t._v(" "),s("details",{staticClass:"custom-block details"},[s("summary",[t._v("DETAILS")]),t._v(" "),s("p",[t._v("All accounts created with Anchor are laid out as follows: "),s("code",[t._v("8-byte-discriminator || borsh serialized data")]),t._v(". The 8-byte-discriminator is created from the first 8 bytes of the\n"),s("code",[t._v("Sha256")]),t._v(" hash of the account's type--using the example above, "),s("code",[t._v('sha256("account:MyAccount")[..8]')]),t._v(".\nThe "),s("code",[t._v("account:")]),t._v(" is a fixed prefix.")]),t._v(" "),s("p",[t._v("Importantly, this allows a program to know for certain an account is indeed of a given type.\nWithout it, a program would be vulnerable to account injection attacks, where a malicious user\nspecifies an account of an unexpected type, causing the program to do unexpected things.")]),t._v(" "),s("p",[t._v("On account creation, this 8-byte discriminator doesn't exist, since the account storage is\nzeroed. The first time an Anchor program mutates an account, this discriminator is prepended\nto the account storage array and all subsequent accesses to the account (not decorated with\n"),s("code",[t._v("#[account(init)]")]),t._v(") will check for this discriminator.")])]),t._v(" "),s("h3",{attrs:{id:"update-instruction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#update-instruction"}},[t._v("#")]),t._v(" "),s("code",[t._v("update")]),t._v(" instruction")]),t._v(" "),s("p",[t._v("Similarly, the "),s("code",[t._v("Update")]),t._v(" accounts struct is marked with the "),s("code",[t._v("#[account(mut)]")]),t._v(" attribute.\nMarking an account as "),s("code",[t._v("mut")]),t._v(" persists any changes made upon exiting the program.")]),t._v(" "),s("p",[t._v("Here we've covered the basics of how to interact with accounts. In a later tutorial,\nwe'll delve more deeply into deriving "),s("code",[t._v("Accounts")]),t._v(", but for now, just know\nyou must mark an account "),s("code",[t._v("init")]),t._v(" when using it for the first time and "),s("code",[t._v("mut")]),t._v("\nfor persisting changes.")]),t._v(" "),s("h2",{attrs:{id:"creating-and-initializing-accounts"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#creating-and-initializing-accounts"}},[t._v("#")]),t._v(" Creating and Initializing Accounts")]),t._v(" "),s("p",[t._v("We can interact with the program as follows.")]),t._v(" "),s("div",{staticClass:"language-js extra-class"},[s("pre",{pre:!0,attrs:{class:"language-js"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The program to execute.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" program "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("workspace"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Basic1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The Account to create.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myAccount "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("web3"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Keypair"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generate")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create the new account and initialize it with the program.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("rpc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("initialize")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n accounts"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n myAccount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" myAccount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("publicKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n user"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" provider"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("wallet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("publicKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n systemProgram"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" SystemProgram"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("programId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n signers"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("myAccount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")])])])]),s("p",[t._v("The last element passed into the method is common amongst all dynamically generated\nmethods on the "),s("code",[t._v("rpc")]),t._v(" namespace, containing several options for a transaction. Here,\nwe specify the "),s("code",[t._v("accounts")]),t._v(" field, an object of all the addresses the transaction\nneeds to touch, and the "),s("code",[t._v("signers")]),t._v(" array of all "),s("code",[t._v("Signer")]),t._v(" objects needed to sign the\ntransaction. Because "),s("code",[t._v("myAccount")]),t._v(" is being created, the Solana runtime requires it\nto sign the transaction.")]),t._v(" "),s("details",{staticClass:"custom-block details"},[s("summary",[t._v("DETAILS")]),t._v(" "),s("p",[t._v("If you've developed on Solana before, you might notice two things 1) the ordering of the accounts doesn't\nmatter and 2) the "),s("code",[t._v("isWritable")]),t._v(" and "),s("code",[t._v("isSigner")]),t._v("\noptions are not specified on the account anywhere. In both cases, the framework takes care\nof these details for you, by reading the IDL.")])]),t._v(" "),s("p",[t._v("As before, we can run the example tests.")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("anchor test\n")])])]),s("h2",{attrs:{id:"next-steps"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#next-steps"}},[t._v("#")]),t._v(" Next Steps")]),t._v(" "),s("p",[t._v("We've covered all the basics of developing applications using Anchor. However, we've\nleft out one important aspect to ensure the security of our programs--validating input\nand access control. We'll cover that next.")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[18],{411:function(t,a,s){"use strict";s.r(a);var n=s(29),e=Object(n.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"arguments-and-accounts"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#arguments-and-accounts"}},[t._v("#")]),t._v(" Arguments and Accounts")]),t._v(" "),s("p",[t._v("This tutorial covers the basics of creating and mutating accounts using Anchor.\nIt's recommended to read "),s("RouterLink",{attrs:{to:"/tutorials/tutorial-0.html"}},[t._v("Tutorial 0")]),t._v(" first, as this tutorial will\nbuild on top of it.")],1),t._v(" "),s("h2",{attrs:{id:"clone-the-repo"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#clone-the-repo"}},[t._v("#")]),t._v(" Clone the Repo")]),t._v(" "),s("p",[t._v("To get started, clone the repo.")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone https://github.com/project-serum/anchor\n")])])]),s("p",[t._v("Change directories to the "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-1",target:"_blank",rel:"noopener noreferrer"}},[t._v("example"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" anchor/examples/tutorial/basic-1\n")])])]),s("p",[t._v("And install any additional JavaScript dependencies:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("yarn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v("\n")])])]),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("We define our program as follows")]),t._v(" "),s("div",{staticClass:"language-rs extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rs"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("declare_id!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("basic_1")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("initialize")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Initialize")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" my_account "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("update")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Update")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" my_account "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("data "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Initialize")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(init, payer = user, space = 8 + 8)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("MyAccount")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" system_program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Program")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("System")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Update")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" my_account"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("MyAccount")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("MyAccount")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" data"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Some new syntax elements are introduced here.")]),t._v(" "),s("h3",{attrs:{id:"initialize-instruction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#initialize-instruction"}},[t._v("#")]),t._v(" "),s("code",[t._v("initialize")]),t._v(" instruction")]),t._v(" "),s("p",[t._v("First, let's start with the initialize instruction. Notice the "),s("code",[t._v("data")]),t._v(" argument passed into the program. This argument and any other valid\nRust types can be passed to the instruction to define inputs to the program.")]),t._v(" "),s("p",[t._v("Additionally,\nnotice how we take a mutable reference to "),s("code",[t._v("my_account")]),t._v(" and assign the "),s("code",[t._v("data")]),t._v(" to it. This leads us to\nthe "),s("code",[t._v("Initialize")]),t._v(" struct, deriving "),s("code",[t._v("Accounts")]),t._v(". There are two things to notice about "),s("code",[t._v("Initialize")]),t._v(".")]),t._v(" "),s("ol",[s("li",[t._v("The "),s("code",[t._v("my_account")]),t._v(" field is of type "),s("code",[t._v("Account<'info, MyAccount>")]),t._v(" and the deserialized data structure is "),s("code",[t._v("MyAccount")]),t._v(".")]),t._v(" "),s("li",[t._v("The "),s("code",[t._v("my_account")]),t._v(" field is marked with the "),s("code",[t._v("init")]),t._v(" attribute. This will create a new\naccount owned by the current program, zero initialized. When using "),s("code",[t._v("init")]),t._v(", one must also provide\n"),s("code",[t._v("payer")]),t._v(", which will fund the account creation, "),s("code",[t._v("space")]),t._v(", which defines how large the account should be,\nand the "),s("code",[t._v("system_program")]),t._v(", which is required by the runtime for creating the account.")])]),t._v(" "),s("details",{staticClass:"custom-block details"},[s("summary",[t._v("DETAILS")]),t._v(" "),s("p",[t._v("All accounts created with Anchor are laid out as follows: "),s("code",[t._v("8-byte-discriminator || borsh serialized data")]),t._v(". The 8-byte-discriminator is created from the first 8 bytes of the\n"),s("code",[t._v("Sha256")]),t._v(" hash of the account's type--using the example above, "),s("code",[t._v('sha256("account:MyAccount")[..8]')]),t._v(".\nThe "),s("code",[t._v("account:")]),t._v(" is a fixed prefix.")]),t._v(" "),s("p",[t._v("Importantly, this allows a program to know for certain an account is indeed of a given type.\nWithout it, a program would be vulnerable to account injection attacks, where a malicious user\nspecifies an account of an unexpected type, causing the program to do unexpected things.")]),t._v(" "),s("p",[t._v("On account creation, this 8-byte discriminator doesn't exist, since the account storage is\nzeroed. The first time an Anchor program mutates an account, this discriminator is prepended\nto the account storage array and all subsequent accesses to the account (not decorated with\n"),s("code",[t._v("#[account(init)]")]),t._v(") will check for this discriminator.")])]),t._v(" "),s("h3",{attrs:{id:"update-instruction"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#update-instruction"}},[t._v("#")]),t._v(" "),s("code",[t._v("update")]),t._v(" instruction")]),t._v(" "),s("p",[t._v("Similarly, the "),s("code",[t._v("Update")]),t._v(" accounts struct is marked with the "),s("code",[t._v("#[account(mut)]")]),t._v(" attribute.\nMarking an account as "),s("code",[t._v("mut")]),t._v(" persists any changes made upon exiting the program.")]),t._v(" "),s("p",[t._v("Here we've covered the basics of how to interact with accounts. In a later tutorial,\nwe'll delve more deeply into deriving "),s("code",[t._v("Accounts")]),t._v(", but for now, just know\nyou must mark an account "),s("code",[t._v("init")]),t._v(" when using it for the first time and "),s("code",[t._v("mut")]),t._v("\nfor persisting changes.")]),t._v(" "),s("h2",{attrs:{id:"creating-and-initializing-accounts"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#creating-and-initializing-accounts"}},[t._v("#")]),t._v(" Creating and Initializing Accounts")]),t._v(" "),s("p",[t._v("We can interact with the program as follows.")]),t._v(" "),s("div",{staticClass:"language-js extra-class"},[s("pre",{pre:!0,attrs:{class:"language-js"}},[s("code",[s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The program to execute.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" program "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("workspace"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Basic1"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// The Account to create.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" myAccount "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("web3"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Keypair"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("generate")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Create the new account and initialize it with the program.")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("rpc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("initialize")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("new")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("anchor"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("BN")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1234")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n accounts"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n myAccount"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" myAccount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("publicKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n user"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" provider"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("wallet"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("publicKey"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n systemProgram"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" SystemProgram"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("programId"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n signers"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("myAccount"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")])])])]),s("p",[t._v("The last element passed into the method is common amongst all dynamically generated\nmethods on the "),s("code",[t._v("rpc")]),t._v(" namespace, containing several options for a transaction. Here,\nwe specify the "),s("code",[t._v("accounts")]),t._v(" field, an object of all the addresses the transaction\nneeds to touch, and the "),s("code",[t._v("signers")]),t._v(" array of all "),s("code",[t._v("Signer")]),t._v(" objects needed to sign the\ntransaction. Because "),s("code",[t._v("myAccount")]),t._v(" is being created, the Solana runtime requires it\nto sign the transaction.")]),t._v(" "),s("details",{staticClass:"custom-block details"},[s("summary",[t._v("DETAILS")]),t._v(" "),s("p",[t._v("If you've developed on Solana before, you might notice two things 1) the ordering of the accounts doesn't\nmatter and 2) the "),s("code",[t._v("isWritable")]),t._v(" and "),s("code",[t._v("isSigner")]),t._v("\noptions are not specified on the account anywhere. In both cases, the framework takes care\nof these details for you, by reading the IDL.")])]),t._v(" "),s("p",[t._v("As before, we can run the example tests.")]),t._v(" "),s("div",{staticClass:"language- extra-class"},[s("pre",{pre:!0,attrs:{class:"language-text"}},[s("code",[t._v("anchor test\n")])])]),s("h2",{attrs:{id:"next-steps"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#next-steps"}},[t._v("#")]),t._v(" Next Steps")]),t._v(" "),s("p",[t._v("We've covered all the basics of developing applications using Anchor. However, we've\nleft out one important aspect to ensure the security of our programs--validating input\nand access control. We'll cover that next.")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/19.8bcaf6fe.js b/assets/js/19.b9ce785c.js similarity index 99% rename from assets/js/19.8bcaf6fe.js rename to assets/js/19.b9ce785c.js index 65267975..435043e4 100644 --- a/assets/js/19.8bcaf6fe.js +++ b/assets/js/19.b9ce785c.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{411:function(t,a,s){"use strict";s.r(a);var n=s(29),e=Object(n.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"account-constraints-and-access-control"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#account-constraints-and-access-control"}},[t._v("#")]),t._v(" Account Constraints and Access Control")]),t._v(" "),s("p",[t._v("This tutorial covers how to specify constraints and access control on accounts, a problem\nsomewhat unique to the parallel nature of Solana.")]),t._v(" "),s("p",[t._v("On Solana, a transaction must specify all accounts required for execution. And because an untrusted client specifies those accounts, a program must responsibly validate all such accounts are what the client claims they are--in addition to any instruction specific access control the program needs to do.")]),t._v(" "),s("p",[t._v("For example, you could imagine easily writing a faulty token program that forgets to check if the "),s("strong",[t._v("signer")]),t._v(" of a transaction claiming to be the "),s("strong",[t._v("owner")]),t._v(" of a Token "),s("code",[t._v("Account")]),t._v(" actually matches the "),s("strong",[t._v("owner")]),t._v(" on that account. Furthermore, imagine what might happen if the program expects a "),s("code",[t._v("Mint")]),t._v(" account but a malicious user gives a token "),s("code",[t._v("Account")]),t._v(".")]),t._v(" "),s("p",[t._v("To address these problems, Anchor provides several types, traits, and macros. It's easiest to understand by seeing how they're used in an example, but a couple include")]),t._v(" "),s("ul",[s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Accounts"),s("OutboundLink")],1),t._v(": derive macro implementing the "),s("code",[t._v("Accounts")]),t._v(" "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("trait"),s("OutboundLink")],1),t._v(", allowing a struct to transform\nfrom the untrusted "),s("code",[t._v("&[AccountInfo]")]),t._v(" slice given to a Solana program into a validated struct\nof deserialized account types.")]),t._v(" "),s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/attr.account.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("#[account]"),s("OutboundLink")],1),t._v(": attribute macro implementing "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.AccountSerialize.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("AccountSerialize"),s("OutboundLink")],1),t._v(" and "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.AnchorDeserialize.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("AccountDeserialize"),s("OutboundLink")],1),t._v(", automatically prepending a unique 8 byte discriminator to the account array. The discriminator is defined by the first 8 bytes of the "),s("code",[t._v("Sha256")]),t._v(" hash of the account's Rust identifier--i.e., the struct type name--and ensures no account can be substituted for another.")]),t._v(" "),s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/accounts/account/struct.Account.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Account"),s("OutboundLink")],1),t._v(": a wrapper type for a deserialized account implementing "),s("code",[t._v("AccountDeserialize")]),t._v(". Using this type within an "),s("code",[t._v("Accounts")]),t._v(" struct will ensure the account is "),s("strong",[t._v("owned")]),t._v(" by the address defined by "),s("code",[t._v("declare_id!")]),t._v(" where the inner account was defined.")])]),t._v(" "),s("p",[t._v("With the above, we can define preconditions for any instruction handler expecting a certain set of\naccounts, allowing us to more easily reason about the security of our programs.")]),t._v(" "),s("h2",{attrs:{id:"clone-the-repo"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#clone-the-repo"}},[t._v("#")]),t._v(" Clone the Repo")]),t._v(" "),s("p",[t._v("To get started, clone the repo.")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone https://github.com/project-serum/anchor\n")])])]),s("p",[t._v("Change directories to the "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-2",target:"_blank",rel:"noopener noreferrer"}},[t._v("example"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" anchor/examples/tutorial/basic-2\n")])])]),s("p",[t._v("And install any additional JavaScript dependencies:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("yarn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v("\n")])])]),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("Here we have a simple "),s("strong",[t._v("Counter")]),t._v(" program, where anyone can create a counter, but only the assigned\n"),s("strong",[t._v("authority")]),t._v(" can increment it.")]),t._v(" "),s("div",{staticClass:"language-rs extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rs"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("declare_id!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("basic_2")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("create")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Create")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Pubkey")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("authority "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Create")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(init, payer = user, space = 8 + 40)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" system_program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Program")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("System")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut, has_one = authority)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Pubkey")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("If you've gone through the previous tutorials the "),s("code",[t._v("create")]),t._v(" instruction should be straightforward.\nLet's focus on the "),s("code",[t._v("increment")]),t._v(" instruction, specifically the "),s("code",[t._v("Increment")]),t._v(" struct deriving\n"),s("code",[t._v("Accounts")]),t._v(".")]),t._v(" "),s("div",{staticClass:"language-rust extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rust"}},[s("code",[s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut, has_one = authority)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Here, a couple "),s("code",[t._v("#[account(..)]")]),t._v(" attributes are used.")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("mut")]),t._v(": tells the program to persist all changes to the account.")]),t._v(" "),s("li",[s("code",[t._v("has_one")]),t._v(": enforces the constraint that "),s("code",[t._v("Increment.counter.authority == Increment.authority.key")]),t._v(".")])]),t._v(" "),s("p",[t._v("Another new concept here is the "),s("code",[t._v("Signer")]),t._v(" type. This enforces the constraint that the "),s("code",[t._v("authority")]),t._v("\naccount "),s("strong",[t._v("signed")]),t._v(" the transaction. However, anchor doesn't fetch the data on that account.")]),t._v(" "),s("p",[t._v("If any of these constraints do not hold, then the "),s("code",[t._v("increment")]),t._v(" instruction will never be executed.\nThis allows us to completely separate account validation from our program's business logic, allowing us\nto reason about each concern more easily. For more, see the full "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("list"),s("OutboundLink")],1),t._v(" of account constraints.")]),t._v(" "),s("h2",{attrs:{id:"next-steps"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#next-steps"}},[t._v("#")]),t._v(" Next Steps")]),t._v(" "),s("p",[t._v("We've covered the basics for writing a single program using Anchor on Solana. But the power of\nblockchains come not from a single program, but from combining multiple "),s("em",[t._v("composable")]),t._v(" programs\n(buzzword...check). Next, we'll see how to call one program from another.")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{412:function(t,a,s){"use strict";s.r(a);var n=s(29),e=Object(n.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"account-constraints-and-access-control"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#account-constraints-and-access-control"}},[t._v("#")]),t._v(" Account Constraints and Access Control")]),t._v(" "),s("p",[t._v("This tutorial covers how to specify constraints and access control on accounts, a problem\nsomewhat unique to the parallel nature of Solana.")]),t._v(" "),s("p",[t._v("On Solana, a transaction must specify all accounts required for execution. And because an untrusted client specifies those accounts, a program must responsibly validate all such accounts are what the client claims they are--in addition to any instruction specific access control the program needs to do.")]),t._v(" "),s("p",[t._v("For example, you could imagine easily writing a faulty token program that forgets to check if the "),s("strong",[t._v("signer")]),t._v(" of a transaction claiming to be the "),s("strong",[t._v("owner")]),t._v(" of a Token "),s("code",[t._v("Account")]),t._v(" actually matches the "),s("strong",[t._v("owner")]),t._v(" on that account. Furthermore, imagine what might happen if the program expects a "),s("code",[t._v("Mint")]),t._v(" account but a malicious user gives a token "),s("code",[t._v("Account")]),t._v(".")]),t._v(" "),s("p",[t._v("To address these problems, Anchor provides several types, traits, and macros. It's easiest to understand by seeing how they're used in an example, but a couple include")]),t._v(" "),s("ul",[s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Accounts"),s("OutboundLink")],1),t._v(": derive macro implementing the "),s("code",[t._v("Accounts")]),t._v(" "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("trait"),s("OutboundLink")],1),t._v(", allowing a struct to transform\nfrom the untrusted "),s("code",[t._v("&[AccountInfo]")]),t._v(" slice given to a Solana program into a validated struct\nof deserialized account types.")]),t._v(" "),s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/attr.account.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("#[account]"),s("OutboundLink")],1),t._v(": attribute macro implementing "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.AccountSerialize.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("AccountSerialize"),s("OutboundLink")],1),t._v(" and "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/trait.AnchorDeserialize.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("AccountDeserialize"),s("OutboundLink")],1),t._v(", automatically prepending a unique 8 byte discriminator to the account array. The discriminator is defined by the first 8 bytes of the "),s("code",[t._v("Sha256")]),t._v(" hash of the account's Rust identifier--i.e., the struct type name--and ensures no account can be substituted for another.")]),t._v(" "),s("li",[s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/accounts/account/struct.Account.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("Account"),s("OutboundLink")],1),t._v(": a wrapper type for a deserialized account implementing "),s("code",[t._v("AccountDeserialize")]),t._v(". Using this type within an "),s("code",[t._v("Accounts")]),t._v(" struct will ensure the account is "),s("strong",[t._v("owned")]),t._v(" by the address defined by "),s("code",[t._v("declare_id!")]),t._v(" where the inner account was defined.")])]),t._v(" "),s("p",[t._v("With the above, we can define preconditions for any instruction handler expecting a certain set of\naccounts, allowing us to more easily reason about the security of our programs.")]),t._v(" "),s("h2",{attrs:{id:"clone-the-repo"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#clone-the-repo"}},[t._v("#")]),t._v(" Clone the Repo")]),t._v(" "),s("p",[t._v("To get started, clone the repo.")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("git")]),t._v(" clone https://github.com/project-serum/anchor\n")])])]),s("p",[t._v("Change directories to the "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-2",target:"_blank",rel:"noopener noreferrer"}},[t._v("example"),s("OutboundLink")],1),t._v(".")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token builtin class-name"}},[t._v("cd")]),t._v(" anchor/examples/tutorial/basic-2\n")])])]),s("p",[t._v("And install any additional JavaScript dependencies:")]),t._v(" "),s("div",{staticClass:"language-bash extra-class"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[s("span",{pre:!0,attrs:{class:"token function"}},[t._v("yarn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("install")]),t._v("\n")])])]),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("Here we have a simple "),s("strong",[t._v("Counter")]),t._v(" program, where anyone can create a counter, but only the assigned\n"),s("strong",[t._v("authority")]),t._v(" can increment it.")]),t._v(" "),s("div",{staticClass:"language-rs extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rs"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("declare_id!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("basic_2")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("create")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Create")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Pubkey")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("authority "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("increment")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("let")]),t._v(" counter "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("&")]),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mut")]),t._v(" ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("accounts"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("count "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Create")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(init, payer = user, space = 8 + 40)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" user"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" system_program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Program")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("System")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut, has_one = authority)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Counter")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Pubkey")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" count"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("u64")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("If you've gone through the previous tutorials the "),s("code",[t._v("create")]),t._v(" instruction should be straightforward.\nLet's focus on the "),s("code",[t._v("increment")]),t._v(" instruction, specifically the "),s("code",[t._v("Increment")]),t._v(" struct deriving\n"),s("code",[t._v("Accounts")]),t._v(".")]),t._v(" "),s("div",{staticClass:"language-rust extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rust"}},[s("code",[s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Increment")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[account(mut, has_one = authority)]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" counter"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Account")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Counter")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" authority"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Signer")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token lifetime-annotation symbol"}},[t._v("'info")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Here, a couple "),s("code",[t._v("#[account(..)]")]),t._v(" attributes are used.")]),t._v(" "),s("ul",[s("li",[s("code",[t._v("mut")]),t._v(": tells the program to persist all changes to the account.")]),t._v(" "),s("li",[s("code",[t._v("has_one")]),t._v(": enforces the constraint that "),s("code",[t._v("Increment.counter.authority == Increment.authority.key")]),t._v(".")])]),t._v(" "),s("p",[t._v("Another new concept here is the "),s("code",[t._v("Signer")]),t._v(" type. This enforces the constraint that the "),s("code",[t._v("authority")]),t._v("\naccount "),s("strong",[t._v("signed")]),t._v(" the transaction. However, anchor doesn't fetch the data on that account.")]),t._v(" "),s("p",[t._v("If any of these constraints do not hold, then the "),s("code",[t._v("increment")]),t._v(" instruction will never be executed.\nThis allows us to completely separate account validation from our program's business logic, allowing us\nto reason about each concern more easily. For more, see the full "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/derive.Accounts.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("list"),s("OutboundLink")],1),t._v(" of account constraints.")]),t._v(" "),s("h2",{attrs:{id:"next-steps"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#next-steps"}},[t._v("#")]),t._v(" Next Steps")]),t._v(" "),s("p",[t._v("We've covered the basics for writing a single program using Anchor on Solana. But the power of\nblockchains come not from a single program, but from combining multiple "),s("em",[t._v("composable")]),t._v(" programs\n(buzzword...check). Next, we'll see how to call one program from another.")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/21.2312ea83.js b/assets/js/21.b31f2925.js similarity index 63% rename from assets/js/21.2312ea83.js rename to assets/js/21.b31f2925.js index 8402d9ac..afd6f27c 100644 --- a/assets/js/21.2312ea83.js +++ b/assets/js/21.b31f2925.js @@ -1 +1 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[21],{414:function(t,a,s){"use strict";s.r(a);var r=s(29),e=Object(r.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"errors"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#errors"}},[t._v("#")]),t._v(" Errors")]),t._v(" "),s("p",[t._v("If you've ever programmed on a blockchain, you've probably been frustrated by\neither non existent or opaque error codes. Anchor attempts to address this by\nproviding the "),s("code",[t._v("#[error_code]")]),t._v(" attribute, which can be used to create typed Errors with\ndescriptive messages that automatically propagate to the client.")]),t._v(" "),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("For example,")]),t._v(" "),s("div",{staticClass:"language-rust extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rust"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("errors")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("_ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Err")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("error!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("ErrorCode")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Hello")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[error_code]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("enum")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("ErrorCode")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[msg("),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"This is an error message clients will automatically display"')]),t._v(")]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Observe the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/attr.error_code.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("#[error_code]"),s("OutboundLink")],1),t._v(" attribute on the "),s("code",[t._v("ErrorCode")]),t._v(" enum.\nThis macro generates internal anchor code that helps anchor turn the error code into an error and display it properly.")]),t._v(" "),s("p",[t._v("To create an error, use the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.error.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("error!")]),s("OutboundLink")],1),t._v(" macro together with an error code. This macro creates an "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/error/struct.AnchorError.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("AnchorError")]),s("OutboundLink")],1),t._v(" that includes helpful information like the file and line the error was created in.")]),t._v(" "),s("p",[t._v("To make writing errors even easier, anchor also provides the ["),s("code",[t._v("err!")]),t._v("](https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.err.html and the ["),s("code",[t._v("require!")]),t._v("](https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.require.html macros.")]),t._v(" "),s("h2",{attrs:{id:"using-the-client"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-the-client"}},[t._v("#")]),t._v(" Using the Client")]),t._v(" "),s("p",[t._v("When using the client, we get the error message.")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" tx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("rpc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n assert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" errMsg "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"This is an error message clients will automatically display"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n assert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("toString")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" errMsg"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("It's that easy. 😃")]),t._v(" "),s("p",[t._v("To run the full example, go "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-4",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),s("OutboundLink")],1),t._v(".")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file +(window.webpackJsonp=window.webpackJsonp||[]).push([[21],{414:function(t,a,s){"use strict";s.r(a);var r=s(29),e=Object(r.a)({},(function(){var t=this,a=t.$createElement,s=t._self._c||a;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"errors"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#errors"}},[t._v("#")]),t._v(" Errors")]),t._v(" "),s("p",[t._v("If you've ever programmed on a blockchain, you've probably been frustrated by\neither non existent or opaque error codes. Anchor attempts to address this by\nproviding the "),s("code",[t._v("#[error_code]")]),t._v(" attribute, which can be used to create typed Errors with\ndescriptive messages that automatically propagate to the client.")]),t._v(" "),s("h2",{attrs:{id:"defining-a-program"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#defining-a-program"}},[t._v("#")]),t._v(" Defining a Program")]),t._v(" "),s("p",[t._v("For example,")]),t._v(" "),s("div",{staticClass:"language-rust extra-class"},[s("pre",{pre:!0,attrs:{class:"language-rust"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token namespace"}},[t._v("anchor_lang"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),t._v("prelude"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")])]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[program]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("mod")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token module-declaration namespace"}},[t._v("errors")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("use")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("super")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("fn")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token function-definition function"}},[t._v("hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("_ctx"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Context")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("->")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Result")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("<")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v(">")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Err")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token macro property"}},[t._v("error!")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("ErrorCode")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("::")]),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[derive(Accounts)]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("struct")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("Hello")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[error_code]")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("pub")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("enum")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token type-definition class-name"}},[t._v("ErrorCode")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token attribute attr-name"}},[t._v("#[msg("),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"This is an error message clients will automatically display"')]),t._v(")]")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token class-name"}},[t._v("Hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("Observe the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/attr.error_code.html",target:"_blank",rel:"noopener noreferrer"}},[t._v("#[error_code]"),s("OutboundLink")],1),t._v(" attribute on the "),s("code",[t._v("ErrorCode")]),t._v(" enum.\nThis macro generates internal anchor code that helps anchor turn the error code into an error and display it properly.")]),t._v(" "),s("p",[t._v("To create an error, use the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.error.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("error!")]),s("OutboundLink")],1),t._v(" macro together with an error code. This macro creates an "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/error/struct.AnchorError.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("AnchorError")]),s("OutboundLink")],1),t._v(" that includes helpful information like the file and line the error was created in.")]),t._v(" "),s("p",[t._v("To make writing errors even easier, anchor also provides the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.err.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("err!")]),s("OutboundLink")],1),t._v(" and the "),s("a",{attrs:{href:"https://docs.rs/anchor-lang/latest/anchor_lang/prelude/macro.require.html",target:"_blank",rel:"noopener noreferrer"}},[s("code",[t._v("require!")]),s("OutboundLink")],1),t._v(" macros.")]),t._v(" "),s("h2",{attrs:{id:"using-the-client"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#using-the-client"}},[t._v("#")]),t._v(" Using the Client")]),t._v(" "),s("p",[t._v("When using the client, we get the error message.")]),t._v(" "),s("div",{staticClass:"language-javascript extra-class"},[s("pre",{pre:!0,attrs:{class:"language-javascript"}},[s("code",[s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("try")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" tx "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("await")]),t._v(" program"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("rpc"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("hello")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n assert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("ok")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("catch")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),s("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("const")]),t._v(" errMsg "),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token string"}},[t._v('"This is an error message clients will automatically display"')]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n assert"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("equal")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),s("span",{pre:!0,attrs:{class:"token function"}},[t._v("toString")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" errMsg"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v("\n"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),s("p",[t._v("It's that easy. 😃")]),t._v(" "),s("p",[t._v("To run the full example, go "),s("a",{attrs:{href:"https://github.com/project-serum/anchor/tree/master/examples/tutorial/basic-4",target:"_blank",rel:"noopener noreferrer"}},[t._v("here"),s("OutboundLink")],1),t._v(".")])])}),[],!1,null,null,null);a.default=e.exports}}]); \ No newline at end of file diff --git a/assets/js/app.dfe95c3c.js b/assets/js/app.b2f13cd7.js similarity index 96% rename from assets/js/app.dfe95c3c.js rename to assets/js/app.b2f13cd7.js index 435ee918..e331ff98 100644 --- a/assets/js/app.dfe95c3c.js +++ b/assets/js/app.b2f13cd7.js @@ -1,8 +1,8 @@ -(window.webpackJsonp=window.webpackJsonp||[]).push([[0],[]]);!function(t){function e(e){for(var r,a,u=e[0],c=e[1],s=e[2],l=0,p=[];l=n.length?{value:void 0,done:!0}:(t=r(n,o),e.index+=t.length,{value:t,done:!1})}))},function(t,e,n){var r=n(0),o=n(5),i=n(10),a=n(25),u=n(90),c=n(67),s=n(32),f=n(84).CONFIGURABLE,l=s.get,p=s.enforce,h=String(String).split("String");(t.exports=function(t,e,n,c){var s,l=!!c&&!!c.unsafe,d=!!c&&!!c.enumerable,v=!!c&&!!c.noTargetGet,y=c&&void 0!==c.name?c.name:e;o(n)&&("Symbol("===String(y).slice(0,7)&&(y="["+String(y).replace(/^Symbol\(([^)]*)\)/,"$1")+"]"),(!i(n,"name")||f&&n.name!==y)&&a(n,"name",y),(s=p(n)).source||(s.source=h.join("string"==typeof y?y:""))),t!==r?(l?!v&&t[e]&&(d=!0):delete t[e],d?t[e]=n:a(t,e,n)):d?t[e]=n:u(e,n)})(Function.prototype,"toString",(function(){return o(this)&&l(this).source||c(this)}))},function(t,e){var n=Array.isArray;t.exports=n},function(t,e,n){var r=n(0),o=n(142),i=n(143),a=n(120),u=n(25),c=n(4),s=c("iterator"),f=c("toStringTag"),l=a.values,p=function(t,e){if(t){if(t[s]!==l)try{u(t,s,l)}catch(e){t[s]=l}if(t[f]||u(t,f,e),o[e])for(var n in a)if(t[n]!==a[n])try{u(t,n,a[n])}catch(e){t[n]=a[n]}}};for(var h in o)p(r[h]&&r[h].prototype,h);p(i,"DOMTokenList")},function(t,e,n){var r=n(155),o="object"==typeof self&&self&&self.Object===Object&&self,i=r||o||Function("return this")();t.exports=i},function(t,e,n){var r=n(0),o=n(68),i=r.String;t.exports=function(t){if("Symbol"===o(t))throw TypeError("Cannot convert a Symbol value to a string");return i(t)}},function(t,e,n){var r=n(2),o=r({}.toString),i=r("".slice);t.exports=function(t){return i(o(t),8,-1)}},function(t,e,n){var r=n(83);t.exports=function(t){return r(t.length)}},function(t,e){t.exports=!1},function(t,e,n){var r=n(11),o=n(12),i=n(45);t.exports=r?function(t,e,n){return o.f(t,e,i(1,n))}:function(t,e,n){return t[e]=n,t}},function(t,e,n){var r,o=n(8),i=n(203),a=n(95),u=n(43),c=n(124),s=n(61),f=n(66),l=f("IE_PROTO"),p=function(){},h=function(t){return" + diff --git a/getting-started/installation.html b/getting-started/installation.html index fd94c29b..8d6a1eba 100644 --- a/getting-started/installation.html +++ b/getting-started/installation.html @@ -10,7 +10,7 @@ - + @@ -37,7 +37,7 @@ rustup component add rustfmt

# Install Solana

See the solana docs (opens new window) for installation instructions. On macOS and Linux,

sh -c "$(curl -sSfL https://release.solana.com/v1.9.1/install)"
 

# Install Yarn

Yarn (opens new window) is recommended for JavaScript package management.

npm install -g yarn
 

# Install Anchor

# Install using pre-build binary on x86_64 Linux

Anchor binaries are available via an NPM package @project-serum/anchor-cli (opens new window). Only x86_64 Linux is supported currently, you must build from source for other OS'.

npm i -g @project-serum/anchor-cli
-

# Build from source for other operating systems

For now, we can use Cargo to install the CLI.

cargo install --git https://github.com/project-serum/anchor --tag v0.24.1 anchor-cli --locked
+

# Build from source for other operating systems

For now, we can use Cargo to install the CLI.

cargo install --git https://github.com/project-serum/anchor --tag v0.24.2 anchor-cli --locked
 

On Linux systems you may need to install additional dependencies if cargo install fails. On Ubuntu,

sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev
 

Now verify the CLI is installed properly.

anchor --version
 

# Start a Project

To initialize a new project, simply run:

anchor init <new-project-name>
@@ -50,6 +50,6 @@ rustup component add rustfmt
       
       →
     

- + diff --git a/getting-started/introduction.html b/getting-started/introduction.html index 16f80005..bcd40f8c 100644 --- a/getting-started/introduction.html +++ b/getting-started/introduction.html @@ -10,7 +10,7 @@ - + @@ -35,6 +35,6 @@ →

- + diff --git a/getting-started/projects.html b/getting-started/projects.html index 611436cb..351d130e 100644 --- a/getting-started/projects.html +++ b/getting-started/projects.html @@ -10,7 +10,7 @@ - + @@ -39,6 +39,6 @@ →

- + diff --git a/getting-started/publishing.html b/getting-started/publishing.html index 8f90e226..20cc6813 100644 --- a/getting-started/publishing.html +++ b/getting-started/publishing.html @@ -10,7 +10,7 @@ - + @@ -35,7 +35,7 @@ hosts a catalog of verified programs on Solana both written with and without Anc that authors of smart contracts publish their source to promote best practices for security and transparency.

note

The Anchor Program Registry is currently in alpha testing. For access to publishing please ask on Discord (opens new window).

# Getting Started

The process for publishing is mostly identical to crates.io.

  • Signup for an account here (opens new window).
  • Confirm your email by clicking the link sent to your address.
  • Navigate to your Username -> Account Settings on the top navbar.
  • Click "New Token" in the API Access section.
  • Run anchor login <token> at the command line.

And you're ready to interact with the registry.

# Configuring a Build

Whether your program is written in Anchor or not, all source being published must -have an Anchor.toml to define the build.

An example Anchor.toml config looks as follows,

anchor_version = "0.24.1"
+have an Anchor.toml to define the build.

An example Anchor.toml config looks as follows,

anchor_version = "0.24.2"
 [workspace]
 members = ["programs/multisig"]
 [provider]
@@ -61,6 +61,6 @@ in the example above.

Verifiable Builds

- + diff --git a/getting-started/verification.html b/getting-started/verification.html index 3150b603..43600308 100644 --- a/getting-started/verification.html +++ b/getting-started/verification.html @@ -10,7 +10,7 @@ - + @@ -38,7 +38,7 @@ a verifiable build.

Anchor makes this easy by providing CLI commands to b docker for you. To get started, first make sure you install (opens new window) docker on your local machine.

# Building

To produce a verifiable build, run

anchor build --verifiable
 

# Verifying

To verify a build against a program deployed on mainnet, run

anchor verify -p <lib-name> <program-id>
-

where the <lib-name> is defined by your program's Cargo.toml.

If the program has an IDL, it will also check the IDL deployed on chain matches.

# Images

A docker image for each version of Anchor is published on Docker Hub (opens new window). They are tagged in the form projectserum/build:<version>. For example, to get the image for Anchor v0.24.1 one can run

docker pull projectserum/build:v0.24.1
+

where the <lib-name> is defined by your program's Cargo.toml.

If the program has an IDL, it will also check the IDL deployed on chain matches.

# Images

A docker image for each version of Anchor is published on Docker Hub (opens new window). They are tagged in the form projectserum/build:<version>. For example, to get the image for Anchor v0.24.2 one can run

docker pull projectserum/build:v0.24.2
 

# Removing an Image

In the event you run a verifiable build from the CLI and exit prematurely, it's possible the docker image may still be building in the background.

To remove, run

docker rm -f anchor-program
 

where anchor-program is the name of the image created by default from within @@ -51,6 +51,6 @@ the Anchor CLI.

- + diff --git a/index.html b/index.html index 02a71a8b..42958da4 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ - + @@ -39,6 +39,6 @@

Security

Anchor eliminates many footguns of raw Solana programs by default and allows you to add more security checks without disrupting your business logic.

Code Generation

(De)Serialization, cross-program invocations, account initialization, and more.

IDL & Client Generation

Anchor generates an IDL based on your program and automatically creates a typescript client with it.

Verifiability

Anchor programs can be built verifiably, so users know that the on-chain program matches the code base.

Workspace Management

The CLI helps you manage workspaces with multiple programs, e2e tests, and more.

Compatibility

Anchor programs can interact with all non-anchor programs on Solana.

This documentation is being sunset in favor of The Anchor Book. At this point in time, either documentation may contain information that the other does not.
- + diff --git a/ts/classes/AccountClient.html b/ts/classes/AccountClient.html index 350677fd..eecf6993 100644 --- a/ts/classes/AccountClient.html +++ b/ts/classes/AccountClient.html @@ -1,41 +1,41 @@ -AccountClient | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AccountClient<IDL, A, T>

Type parameters

  • IDL: Idl = Idl

  • A: NullableIdlAccount<IDL> = IDL["accounts"] extends undefined ? IdlAccountDef : NonNullable<IDL["accounts"]>[number]

  • T = TypeDef<A, IdlTypes<IDL>>

Hierarchy

  • AccountClient

Index

Constructors

Accessors

Returns Promise<ProgramAccount<T>[]>

  • associated(...args: (PublicKey | Buffer)[]): Promise<T>
  • deprecated

    since version 14.0.

    Function returning the associated account. Args are keys to associate. Order matters.

    -

    Parameters

    Returns Promise<T>

  • fetchMultiple(addresses: Address[], commitment?: Commitment): Promise<(null | Object)[]>

Returns Promise<T>

  • fetchMultiple(addresses: Address[], commitment?: Commitment): Promise<(null | Object)[]>
  • Returns multiple deserialized accounts. Accounts not found or with wrong discriminator are returned as null.

    Parameters

    • addresses: Address[]

      The addresses of the accounts to fetch.

      -
    • Optional commitment: Commitment

    Returns Promise<(null | Object)[]>

Returns Promise<(null | Object)[]>

  • subscribe(address: Address, commitment?: Commitment): EventEmitter<string | symbol, any>

Returns Promise<null | T>

  • subscribe(address: Address, commitment?: Commitment): EventEmitter<string | symbol, any>
  • unsubscribe(address: Address): Promise<void>
  • unsubscribe(address: Address): Promise<void>

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/AnchorError.html b/ts/classes/AnchorError.html index 4719a545..114244ad 100644 --- a/ts/classes/AnchorError.html +++ b/ts/classes/AnchorError.html @@ -1,6 +1,6 @@ -AnchorError | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Error
    • AnchorError

Index

Constructors

  • new AnchorError(errorCode: ErrorCode, errorMessage: string, errorLogs: string[], logs: string[], origin?: Origin, comparedValues?: ComparedValues): AnchorError
  • Parameters

    • errorCode: ErrorCode
    • errorMessage: string
    • errorLogs: string[]
    • logs: string[]
    • Optional origin: Origin
    • Optional comparedValues: ComparedValues

    Returns AnchorError

Properties

error: { comparedValues?: ComparedValues; errorCode: ErrorCode; errorMessage: string; origin?: Origin }

Type declaration

  • Optional comparedValues?: ComparedValues
  • errorCode: ErrorCode
  • errorMessage: string
  • Optional origin?: Origin
errorLogs: string[]
logs: string[]
message: string
name: string
stack?: string
prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

Type declaration

    • (err: Error, stackTraces: CallSite[]): any
    • +AnchorError | @project-serum/anchor - v0.24.2
      Options
      All
      • Public
      • Public/Protected
      • All
      Menu

      Hierarchy

      • Error
        • AnchorError

      Index

      Constructors

      • new AnchorError(errorCode: ErrorCode, errorMessage: string, errorLogs: string[], logs: string[], origin?: Origin, comparedValues?: ComparedValues): AnchorError
      • Parameters

        • errorCode: ErrorCode
        • errorMessage: string
        • errorLogs: string[]
        • logs: string[]
        • Optional origin: Origin
        • Optional comparedValues: ComparedValues

        Returns AnchorError

      Properties

      error: { comparedValues?: ComparedValues; errorCode: ErrorCode; errorMessage: string; origin?: Origin }

      Type declaration

      • Optional comparedValues?: ComparedValues
      • errorCode: ErrorCode
      • errorMessage: string
      • Optional origin?: Origin
      errorLogs: string[]
      logs: string[]
      message: string
      name: string
      stack?: string
      prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

      Type declaration

      stackTraceLimit: number

      Accessors

      Methods

      • toString(): string
      • captureStackTrace(targetObject: object, constructorOpt?: Function): void
      • +

        Parameters

        • err: Error
        • stackTraces: CallSite[]

        Returns any

stackTraceLimit: number

Accessors

Methods

  • toString(): string
  • captureStackTrace(targetObject: object, constructorOpt?: Function): void
  • Create .stack property on a target object

    -

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function

    Returns void

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +

Parameters

  • targetObject: object
  • Optional constructorOpt: Function

Returns void

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/AnchorProvider.html b/ts/classes/AnchorProvider.html index 26a2d358..3cc77c10 100644 --- a/ts/classes/AnchorProvider.html +++ b/ts/classes/AnchorProvider.html @@ -1,15 +1,15 @@ -AnchorProvider | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu
+AnchorProvider | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

The network and wallet context used to send transactions paid for and signed by the provider.

-

Hierarchy

  • AnchorProvider

Implements

Index

Constructors

Hierarchy

  • AnchorProvider

Implements

Index

Constructors

  • Parameters

    • connection: Connection

      The cluster connection where the program is deployed.

    • wallet: Wallet

      The wallet used to pay for and sign all transactions.

    • opts: ConfirmOptions

      Transaction confirmation options to use by default.

      -

    Returns AnchorProvider

Properties

connection: Connection
wallet: Wallet

Methods

Returns AnchorProvider

Properties

connection: Connection
wallet: Wallet

Methods

  • Sends the given transaction, paid for and signed by the provider's wallet.

    Parameters

    • tx: Transaction

      The transaction to send.

      @@ -17,17 +17,17 @@ by the provider.

      The signers of the transaction.

    • Optional opts: ConfirmOptions

      Transaction confirmation options.

      -

    Returns Promise<string>

Returns Promise<string>

Returns Promise<SuccessfulTxSimulationResponse>

deprecated
state?: StateClient<IDL>
+
deprecated
state?: StateClient<IDL>

A client for the program state. Similar to the base Program client, one can use this to send transactions and read accounts for the state abstraction.

-
transaction: TransactionNamespace<IDL, AllInstructions<IDL>>
+
transaction: TransactionNamespace<IDL, AllInstructions<IDL>>

The namespace provides functions to build Transaction objects for each method of a program.

@@ -161,30 +161,30 @@ Always the last parameter in the method call.

To create an instruction for the increment method above,

const tx = await program.transaction.increment({
accounts: {
counter,
},
});
-
deprecated
views?: ViewNamespace<IDL, AllInstructions<IDL>>

Accessors

views?: ViewNamespace<IDL, AllInstructions<IDL>>

Accessors

  • get idl(): IDL
  • get idl(): IDL

Methods

  • addEventListener(eventName: string, callback: (event: any, slot: number) => void): number

Methods

  • addEventListener(eventName: string, callback: (event: any, slot: number) => void): number
  • Invokes the given callback every time the given event is emitted.

    Parameters

    • eventName: string

      The PascalCase name of the event, provided by the IDL.

    • callback: (event: any, slot: number) => void

      The function to invoke whenever the event is emitted from program logs.

      -
        • (event: any, slot: number): void
        • Parameters

          • event: any
          • slot: number

          Returns void

    Returns number

  • removeEventListener(listener: number): Promise<void>

Returns number

  • removeEventListener(listener: number): Promise<void>
  • Unsubscribes from the given eventName.

    -

    Parameters

    • listener: number

    Returns Promise<void>

  • Generates a Program client by fetching the IDL from the network.

    In order to use this method, an IDL must have been previously initialized via the anchor CLI's anchor idl init command.

    Type parameters

    Parameters

    • address: Address
    • Optional provider: Provider

      The network and wallet context.

      -

    Returns Promise<Program<IDL>>

Returns Promise<Program<IDL>>

  • Fetches an idl from the blockchain.

    In order to use this method, an IDL must have been previously initialized via the anchor CLI's anchor idl init command.

    diff --git a/ts/classes/ProgramError.html b/ts/classes/ProgramError.html index 316cfe26..2b068512 100644 --- a/ts/classes/ProgramError.html +++ b/ts/classes/ProgramError.html @@ -1,6 +1,6 @@ -ProgramError | @project-serum/anchor - v0.24.1
    Options
    All
    • Public
    • Public/Protected
    • All
    Menu

    Hierarchy

    • Error
      • ProgramError

    Index

    Constructors

    • new ProgramError(code: number, msg: string, logs?: string[]): ProgramError

    Properties

    code: number
    logs?: string[]
    message: string
    msg: string
    name: string
    stack?: string
    prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

    Type declaration

      • (err: Error, stackTraces: CallSite[]): any
      • +ProgramError | @project-serum/anchor - v0.24.2
        Options
        All
        • Public
        • Public/Protected
        • All
        Menu

        Hierarchy

        • Error
          • ProgramError

        Index

        Constructors

        • new ProgramError(code: number, msg: string, logs?: string[]): ProgramError

        Properties

        code: number
        logs?: string[]
        message: string
        msg: string
        name: string
        stack?: string
        prepareStackTrace?: (err: Error, stackTraces: CallSite[]) => any

        Type declaration

        stackTraceLimit: number

        Accessors

        • get programErrorStack(): undefined | PublicKey[]

        Methods

        • toString(): string
        • captureStackTrace(targetObject: object, constructorOpt?: Function): void
        • +

          Parameters

          • err: Error
          • stackTraces: CallSite[]

          Returns any

    stackTraceLimit: number

    Accessors

    • get programErrorStack(): undefined | PublicKey[]

    Methods

    • toString(): string
    • captureStackTrace(targetObject: object, constructorOpt?: Function): void
    • Create .stack property on a target object

      -

      Parameters

      • targetObject: object
      • Optional constructorOpt: Function

      Returns void

    • parse(err: any, idlErrors: Map<number, string>): null | ProgramError

    Legend

    • Constructor
    • Property
    • Method
    • Inherited constructor
    • Inherited property
    • Inherited method
    • Property
    • Method
    • Static method

    Settings

    Theme

    Generated using TypeDoc

    \ No newline at end of file +

    Parameters

    • targetObject: object
    • Optional constructorOpt: Function

    Returns void

  • parse(err: any, idlErrors: Map<number, string>): null | ProgramError

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/ProgramErrorStack.html b/ts/classes/ProgramErrorStack.html index 8d817ecb..20b5f7f5 100644 --- a/ts/classes/ProgramErrorStack.html +++ b/ts/classes/ProgramErrorStack.html @@ -1 +1 @@ -ProgramErrorStack | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ProgramErrorStack

Index

Constructors

Properties

Methods

Constructors

Properties

stack: PublicKey[]

Methods

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +ProgramErrorStack | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • ProgramErrorStack

Index

Constructors

Properties

Methods

Constructors

Properties

stack: PublicKey[]

Methods

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/Spl.html b/ts/classes/Spl.html index 858acc7f..1842cdb5 100644 --- a/ts/classes/Spl.html +++ b/ts/classes/Spl.html @@ -1 +1 @@ -Spl | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Spl

Index

Constructors

Methods

Constructors

Methods

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +Spl | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Spl

Index

Constructors

Methods

Constructors

Methods

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/SplTokenCoder.html b/ts/classes/SplTokenCoder.html index 62c17746..709d56e5 100644 --- a/ts/classes/SplTokenCoder.html +++ b/ts/classes/SplTokenCoder.html @@ -1,11 +1,11 @@ -SplTokenCoder | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu
+SplTokenCoder | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

Coder for the SPL token program.

-

Hierarchy

  • SplTokenCoder

Implements

Index

Constructors

Properties

accounts: SplTokenAccountsCoder<string>
+

Hierarchy

  • SplTokenCoder

Implements

Index

Constructors

Properties

accounts: SplTokenAccountsCoder<string>

Account coder.

-
events: SplTokenEventsCoder
+
events: SplTokenEventsCoder

Coder for events.

-
instruction: SplTokenInstructionCoder
+
instruction: SplTokenInstructionCoder

Instruction coder.

-
state: SplTokenStateCoder
+
state: SplTokenStateCoder

Coder for state structs.

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/StateClient.html b/ts/classes/StateClient.html index 9211fb06..ab372fab 100644 --- a/ts/classes/StateClient.html +++ b/ts/classes/StateClient.html @@ -1,22 +1,22 @@ -StateClient | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu
+StateClient | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

A client for the program state. Similar to the base Program client, one can use this to send transactions and read accounts for the state abstraction.

-

Type parameters

Hierarchy

  • StateClient

Index

Constructors

Properties

coder: Coder = ...
instruction: InstructionNamespace<IDL, NullableMethods<IDL>[number]>
+

Type parameters

Hierarchy

  • StateClient

Index

Constructors

Properties

coder: Coder = ...
instruction: InstructionNamespace<IDL, NullableMethods<IDL>[number]>

InstructionNamespace for all state methods.

-
provider: Provider = ...
rpc: RpcNamespace<IDL, NullableMethods<IDL>[number]>
+
provider: Provider = ...
rpc: RpcNamespace<IDL, NullableMethods<IDL>[number]>

RpcNamespace for all state methods.

-
transaction: TransactionNamespace<IDL, NullableMethods<IDL>[number]>
+
transaction: TransactionNamespace<IDL, NullableMethods<IDL>[number]>

TransactionNamespace for all state methods.

-

Accessors

Accessors

Methods

Methods

  • fetch(): Promise<TypeDef<IDL["state"] extends undefined ? IdlTypeDef : NonNullable<IDL["state"]>["struct"], IdlTypes<IDL>>>
  • fetch(): Promise<TypeDef<IDL["state"] extends undefined ? IdlTypeDef : NonNullable<IDL["state"]>["struct"], IdlTypes<IDL>>>
  • subscribe(commitment?: Commitment): EventEmitter<string | symbol, any>
  • subscribe(commitment?: Commitment): EventEmitter<string | symbol, any>
  • Returns an EventEmitter with a "change" event that's fired whenever the state account cahnges.

    -

    Parameters

    Returns EventEmitter<string | symbol, any>

  • unsubscribe(): void
  • unsubscribe(): void

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/Wallet.html b/ts/classes/Wallet.html index d633909c..2fca8501 100644 --- a/ts/classes/Wallet.html +++ b/ts/classes/Wallet.html @@ -1 +1 @@ -Wallet | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • default
    • Wallet

Index

Constructors

Properties

payer: Keypair

Accessors

Methods

  • local(): default

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file +Wallet | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • default
    • Wallet

Index

Constructors

Properties

payer: Keypair

Accessors

Methods

  • local(): default

Legend

  • Constructor
  • Property
  • Method
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Property
  • Method
  • Static method

Settings

Theme

Generated using TypeDoc

\ No newline at end of file diff --git a/ts/classes/web3.Account.html b/ts/classes/web3.Account.html index 96febf7b..222c6228 100644 --- a/ts/classes/web3.Account.html +++ b/ts/classes/web3.Account.html @@ -1,4 +1,4 @@ -Account | @project-serum/anchor - v0.24.1
Options
All
  • Public
  • Public/Protected
  • All
Menu
+Account | @project-serum/anchor - v0.24.2
Options
All
  • Public
  • Public/Protected
  • All
Menu

An account key pair (public and secret keys).

deprecated

since v1.10.0, please use Keypair instead.

Hierarchy

  • Account

Index

Constructors

Accessors

Constructors

  • new Account(secretKey?: number[] | Uint8Array | Buffer): Account