{"id":39,"date":"2021-11-05T13:17:48","date_gmt":"2021-11-05T12:17:48","guid":{"rendered":"https:\/\/abch-330809.firebaseapp.com\/blog\/?p=39"},"modified":"2025-02-19T14:24:17","modified_gmt":"2025-02-19T12:24:17","slug":"solana-tutorial-1-solana-accounts","status":"publish","type":"post","link":"https:\/\/ackee.xyz\/blog\/solana-tutorial-1-solana-accounts\/","title":{"rendered":"Solana Tutorial #1: What Are Solana Accounts?"},"content":{"rendered":"<h3>Accounts<\/h3>\n<p>Everything (almost) is an account on Solana blockchain. Even smart contracts, which are called programs on Solana blockchain are accounts. Sounds weird, right? But don\u2019t worry I will explain it. Let\u2019s start with a description of a structure of an account. The following diagram describes the structure of\u00a0<a href=\"https:\/\/github.com\/solana-labs\/solana\/blob\/62c8fb479272ff8c7c75e39b3efb1720ef961400\/sdk\/program\/src\/account_info.rs#L12\">Solana account<\/a>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-49 size-large\" src=\"https:\/\/ackeeblockchain.com\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-1024x609.png\" alt=\"\" width=\"1024\" height=\"609\" srcset=\"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-1024x609.png 1024w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-300x178.png 300w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-768x457.png 768w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-1536x914.png 1536w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-2048x1218.png 2048w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-370x220.png 370w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-2-2-760x452.png 760w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>You may ask: what is Solana Account information or User space You can think of Solana account information as a namespace for AccountMetadata. This metadata contains all necessary information for Solana runtime to operate this account. The <strong>key<\/strong> of the account is used to uniquly represent this account.<\/p>\n<p>The key may be either:<\/p>\n<ul>\n<li>an ed25519 public key,<\/li>\n<li>a program-derived account address (32byte value forced off the ed25519 curve),<\/li>\n<li>a hash of an ed25519 public key with a 32 character string.<\/li>\n<\/ul>\n<p><b>is_signer<\/b>\u00a0and\u00a0<b>is_writable<\/b> determine a role of this account in transactions. We will explain transactions later, so don\u2019t worry too much about them yet.<\/p>\n<p>The most confusing field can be <strong>owner<\/strong>, mainly because even your account is not owned by you. All accounts on Solana are owned by programs. Some accounts are owned by the System program, and some can be owned by your smart contract (which is just a program, remember?). In the end, the <strong>owner<\/strong> field is just a PubKey, or, you can say the <strong>Program ID of another program<\/strong>. Only the owner can modify user space data and has permission to withdraw lamports. Everyone else can only read the data or credit lamports to an account.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-47 size-large\" src=\"https:\/\/ackeeblockchain.com\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-1024x631.png\" alt=\"\" width=\"1024\" height=\"631\" srcset=\"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-1024x631.png 1024w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-300x185.png 300w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-768x474.png 768w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-1536x947.png 1536w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-2048x1263.png 2048w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-370x228.png 370w, https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-3-4-760x469.png 760w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>To better understand that you are not owner of your account, let&#8217;s take a look at the image above. Bob&#8217;s account is owned by the System Program, but the key field is set to his PubKey. You may wonder if the<strong> SystemProgram\u00a0<\/strong>can debit Bob&#8217;s account without his permission, and the answer is not because SystemProgram checks whenever Bob&#8217;s private key signed transactions to debit his account.\u00a0 That means that only Bob has write access to this account.<\/p>\n<p>The <b>Executable<\/b> field is pretty straightforward. It\u2019s just a boolean which represents if this account is executable which means that Data of this account is a byte code. Such accounts are called programs on Solana, and you can make RPC calls to them. Also it\u2019s important to mention that once the account is marked as executable, you can\u2019t take it back. When the account is marked as executable it becomes a program so it can own another accounts, which means that there can be an account, and his Owner field can be set to Program ID of this program (account).<\/p>\n<p>The<b> Rent epoch<\/b> field just says when you will pay rent for your account next. However, in most cases you pay enough lamports, so your account becomes <a href=\"https:\/\/docs.solana.com\/developing\/programming-model\/accounts#rent-exemption\">rent exempt<\/a> and this field will be set to 0. If you want to know more about rent, check out the <a href=\"https:\/\/docs.solana.com\/developing\/programming-model\/accounts#rent\">Solana docs<\/a>.<\/p>\n<p><b>Lamports<\/b> represent how many <a href=\"https:\/\/docs.solana.com\/terminology#lamport\">Lamports<\/a> an account has. (Balance)<\/p>\n<p><b>Data<\/b> holds an array of bytes which can represent an arbitrary data structure, so it can be used as a state for storing arbitrary information. If an account is marked as\u00a0<a href=\"https:\/\/docs.solana.com\/developing\/programming-model\/accounts#executable\">executable<\/a>\u00a0than this field contains a loaded program.<\/p>\n<p>We hope this helps you better understand Solana programs!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Accounts Everything (almost) is an account on Solana blockchain. Even smart contracts, which are called programs on Solana blockchain are accounts. Sounds weird, right? But don\u2019t worry I will explain it. Let\u2019s start with a description of a structure of an account. The following diagram describes the structure of\u00a0Solana account. You may ask: what is Solana Account information or User space You&hellip;<\/p>\n","protected":false},"author":3,"featured_media":38,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"footnotes":""},"categories":[5,63],"tags":[3],"class_list":["post-39","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-solana","category-tutorial","tag-solana-rust-accounts","post_format-post-format-image"],"aioseo_notices":[],"featured_image_src":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-Cover-2-600x400.png","featured_image_src_square":"https:\/\/ackee.xyz\/blog\/wp-content\/uploads\/2021\/11\/ABCH-Solana-Cover-2-600x518.png","author_info":{"display_name":"Tibor Tribus","author_link":"https:\/\/ackee.xyz\/blog\/author\/tibor-tribus\/"},"_links":{"self":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/comments?post=39"}],"version-history":[{"count":0,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/posts\/39\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media\/38"}],"wp:attachment":[{"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/media?parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/categories?post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ackee.xyz\/blog\/wp-json\/wp\/v2\/tags?post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}