[{"data":1,"prerenderedAt":397},["ShallowReactive",2],{"learn\u002Flearn\u002Fthe-account-model":3,"learn\u002Flearn\u002Fthe-account-model-surround":386},{"id":4,"title":5,"body":6,"category":377,"description":378,"extension":379,"level":377,"meta":380,"navigation":381,"order":368,"path":382,"seo":383,"stem":384,"__hash__":385},"learn\u002Flearn\u002Fthe-account-model.md","Accounts, ownership and PDAs",{"type":7,"value":8,"toc":366},"minimark",[9,18,23,26,105,108,133,137,152,159,163,170,177,180,184,199,209,212,223,227,230,258,265,269,284,287,291],[10,11,12,13,17],"p",{},"Solana has no global state object and no per-contract storage. It has ",[14,15,16],"strong",{},"accounts",", and every piece\nof data the network remembers is one.",[19,20,22],"h2",{"id":21},"the-five-fields","The five fields",[10,24,25],{},"Every account is keyed by a 32-byte address and has the same shape:",[27,28,29,42],"table",{},[30,31,32],"thead",{},[33,34,35,39],"tr",{},[36,37,38],"th",{},"Field",[36,40,41],{},"Meaning",[43,44,45,57,67,82,92],"tbody",{},[33,46,47,54],{},[48,49,50],"td",{},[51,52,53],"code",{},"lamports",[48,55,56],{},"Balance in lamports (1 SOL = 1,000,000,000)",[33,58,59,64],{},[48,60,61],{},[51,62,63],{},"data",[48,65,66],{},"Arbitrary bytes — program state or program code",[33,68,69,74],{},[48,70,71],{},[51,72,73],{},"owner",[48,75,76,77,79,80],{},"The program allowed to modify ",[51,78,63],{}," or debit ",[51,81,53],{},[33,83,84,89],{},[48,85,86],{},[51,87,88],{},"executable",[48,90,91],{},"Whether this account holds a program",[33,93,94,99],{},[48,95,96],{},[51,97,98],{},"rent_epoch",[48,100,101,102],{},"Deprecated; rent-exempt accounts use ",[51,103,104],{},"u64::MAX",[10,106,107],{},"Two rules explain most of Solana's design:",[109,110,111,123],"ol",{},[112,113,114,117,118,122],"li",{},[14,115,116],{},"Only the owner program may modify an account's data or debit its lamports."," Anyone may ",[119,120,121],"em",{},"credit","\nlamports to a writable account, which is how a payment works without the recipient's program\nbeing involved.",[112,124,125,128,129,132],{},[14,126,127],{},"An account's size is fixed when it is created."," Growing it means reallocating with enough\nlamports to stay rent-exempt, up to a ",[14,130,131],{},"10 MiB"," per-account maximum.",[19,134,136],{"id":135},"rent-and-why-there-is-a-deposit","Rent, and why there is a deposit",[10,138,139,140,143,144,147,148,151],{},"Storing data costs validators real resources, so an account must hold a refundable balance:\n",[51,141,142],{},"(data_size + 128) × 3,480 lamports × 2 years",". A 165-byte classic token account needs\n",[14,145,146],{},"2,039,280 lamports"," (≈0.00204 SOL); an 82-byte mint needs ",[14,149,150],{},"1,461,600",".",[10,153,154,155,158],{},"Ongoing rent collection is disabled; this is now a refundable storage deposit. Close the account and\nthe lamports come back to you. Query ",[51,156,157],{},"getMinimumBalanceForRentExemption"," for the live number.",[19,160,162],{"id":161},"programs-are-stateless","Programs are stateless",[10,164,165,166,169],{},"A program is an account with ",[51,167,168],{},"executable = true",", written in a bytecode the runtime can run (sBPF).\nIt executes only over the accounts an instruction hands it, and it can only change those it owns.",[10,171,172,173,176],{},"That is why \"smart contract storage\" does not exist here. A program's memory is the set of accounts\npassed in; its persistent state lives in separate ",[14,174,175],{},"data accounts"," that the program owns. When\npeople say a program is stateless, they mean exactly this.",[10,178,179],{},"Programs are deployed and upgraded through a loader program that owns the executable account; the\nupgrade authority is a separate key, and losing control of it means losing the ability to fix the\nprogram.",[19,181,183],{"id":182},"pdas-addresses-nobody-can-sign-for","PDAs, addresses nobody can sign for",[10,185,186,187,190,191,194,195,198],{},"A ",[14,188,189],{},"program-derived address"," is computed from ",[51,192,193],{},"seeds + program_id + bump"," and then checked to be\n",[14,196,197],{},"off the Ed25519 curve",". Up to 16 seeds, each at most 32 bytes.",[10,200,201,202,205,206,151],{},"Off-curve is the point: no private key corresponds to such an address, so no ordinary signature can\never exist for it. Instead, during a cross-program invocation, the deriving program passes the seeds\nback and the runtime verifies that they hash to the PDA, granting it signer privilege ",[14,203,204],{},"for that\ninvocation only",". That is ",[51,207,208],{},"invoke_signed",[10,210,211],{},"This is how a program controls funds without holding a key. Payvand's allowances work this way: the\npot is a PDA owned by the program, so no person and no server holds a key to it, and spending\nrequires the program's own rules to be satisfied.",[10,213,214,215,218,219,222],{},"Note the two separate steps people conflate: ",[119,216,217],{},"deriving"," an address is pure arithmetic, and\n",[119,220,221],{},"creating"," an account at it costs lamports and a system-program instruction.",[19,224,226],{"id":225},"where-a-token-balance-actually-lives","Where a token balance actually lives",[10,228,229],{},"There are three distinct things:",[231,232,233,243,252],"ul",{},[112,234,235,238,239,242],{},[14,236,237],{},"A mint account"," describes a token: supply, ",[51,240,241],{},"decimals",", and optional mint and freeze authorities.\nAmounts are stored in base units; decimals only affect display.",[112,244,245,248,249,251],{},[14,246,247],{},"A token account"," holds units of exactly one mint. Its own ",[51,250,73],{}," field names the authority that\ncan move them. The account itself is owned by the Token Program (or Token-2022).",[112,253,254,257],{},[14,255,256],{},"A wallet address"," is usually just an on-curve keypair account holding SOL. It is not where your\nUSDC is.",[10,259,260,261,264],{},"The ",[14,262,263],{},"associated token account"," (ATA) is the conventional token account for a given\nwallet + mint + token-program combination, derived deterministically so anyone can find it. The\nToken-2022 program extends this model with optional account and mint extensions, which change account\nsize and add features such as transfer fees or interest.",[19,266,268],{"id":267},"why-write-flags-matter-for-throughput","Why write flags matter for throughput",[10,270,271,272,275,276,279,280,283],{},"The runtime uses ",[14,273,274],{},"Sealevel"," to execute transactions in parallel. Transactions that only ",[119,277,278],{},"read"," an\naccount share it freely; transactions that ",[119,281,282],{},"write"," the same account must be serialized. A hot\nwritable account — one global counter, say — is therefore a throughput bottleneck, while sharded\ndata accounts are not.",[10,285,286],{},"This is a design constraint, not a tuning detail. It is why you will see state split per user, per\nmint and per month rather than kept in one large account.",[19,288,290],{"id":289},"sources","Sources",[231,292,293,313,325,342,359],{},[112,294,295,302,303,302,308],{},[296,297,301],"a",{"href":298,"rel":299},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Faccounts",[300],"nofollow","Accounts"," · ",[296,304,307],{"href":305,"rel":306},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Faccounts\u002Faccount-structure",[300],"Account structure",[296,309,312],{"href":310,"rel":311},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Faccounts\u002Fmodification-rules",[300],"Modification rules",[112,314,315,302,320],{},[296,316,319],{"href":317,"rel":318},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Fprograms",[300],"Programs",[296,321,324],{"href":322,"rel":323},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Fprograms\u002Fbuiltin-programs",[300],"Builtin programs",[112,326,327,302,332,302,337],{},[296,328,331],{"href":329,"rel":330},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Fpda",[300],"PDAs",[296,333,336],{"href":334,"rel":335},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Fpda\u002Fpda-derivation",[300],"PDA derivation",[296,338,341],{"href":339,"rel":340},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Fcore\u002Fcpi",[300],"CPI",[112,343,344,302,349,302,354],{},[296,345,348],{"href":346,"rel":347},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Ftokens",[300],"Tokens",[296,350,353],{"href":351,"rel":352},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Ftokens\u002Fbasics\u002Fcreate-token-account",[300],"Token accounts",[296,355,358],{"href":356,"rel":357},"https:\u002F\u002Fsolana.com\u002Fdocs\u002Ftokens\u002Fextensions",[300],"Token-2022 extensions",[112,360,361],{},[296,362,365],{"href":363,"rel":364},"https:\u002F\u002Fdocs.anza.xyz\u002Fimplemented-proposals\u002Freadonly-accounts",[300],"Anza: read-only accounts and Sealevel",{"title":367,"searchDepth":368,"depth":368,"links":369},"",2,[370,371,372,373,374,375,376],{"id":21,"depth":368,"text":22},{"id":135,"depth":368,"text":136},{"id":161,"depth":368,"text":162},{"id":182,"depth":368,"text":183},{"id":225,"depth":368,"text":226},{"id":267,"depth":368,"text":268},{"id":289,"depth":368,"text":290},"technical","Everything on Solana is an account with five fields and an owner. Why programs are stateless, why a PDA has no private key, and where a token balance really lives.","md",{},true,"\u002Flearn\u002Fthe-account-model",{"title":5,"description":378},"learn\u002Fthe-account-model","bp7WTfy08K-O53-01R2aceMnnuhlfYl_34Ghu237Mxo",[387,392],{"title":388,"path":389,"stem":390,"description":391,"children":-1},"Why the money in the practice app is fake","\u002Flearn\u002Ftest-money-on-devnet","learn\u002Ftest-money-on-devnet","The app can run against a test network, where the dollars and euros are free and worth nothing. How to tell, where to get them, and why that is the best place to learn.",{"title":393,"path":394,"stem":395,"description":396,"children":-1},"Keep two wallets, one to spend and one to save","\u002Flearn\u002Ftwo-wallets","learn\u002Ftwo-wallets","The wallet you connect to apps should hold pocket money, not savings. How to split them, and what a deliberately small balance protects you from.",1795469627807]