(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[602],{1683:function(e,s,r){(window.__NEXT_P=window.__NEXT_P||[]).push(["/world/tables",function(){return r(9360)}])},2588:function(e,s){"use strict";s.Z={src:"/_next/static/media/world-table.39df342f.svg",height:1080,width:1920,blurWidth:0,blurHeight:0}},8986:function(e,s,r){"use strict";r.d(s,{C:function(){return i}});var o=r(7505),l=r(7765),n=r(4737),t=r.n(n);function i(e){let{children:s}=e,r=(0,l.useRef)(null),[n,i]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{if(!r.current)return;let e=Array.from(r.current.querySelectorAll(".line")),s=[];e.forEach((e,r)=>{e.matches(".highlighted")&&s.push(r),/^\s+$/g.test(e.innerHTML)&&e.setAttribute("data-empty","")}),s.length&&e.forEach((e,r)=>{let o=s.reduce((e,s)=>Math.min(e,Math.abs(s-r)),1/0);e.setAttribute("data-highlight-distance",Math.min(o,4).toString())})},[n]),(0,o.jsx)("div",{ref:r,style:{marginTop:"1.5rem"},className:n?t().collapsed:t().expanded,onClick:e=>{e.target instanceof Element&&e.target.closest(".line")&&i(!n)},children:s})}},3307:function(e,s,r){"use strict";r.d(s,{Z:function(){return t}});var o=r(7505),l=r(1689);let n={logo:function(){return(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.25em",fontSize:"32px",fontFamily:"PP Supply Mono",textTransform:"uppercase"},children:[(0,o.jsx)("img",{src:"/images/logos/mud-white.svg",style:{height:"calc(var(--nextra-navbar-height) - 35px)"},alt:"MUD logo"}),"MUD"]})},useNextSeoProps(){let{asPath:e}=(0,l.useRouter)();return{titleTemplate:"/"===e?"MUD – a framework for ambitious Ethereum applications":"%s – MUD"}},project:{link:"https://github.com/latticexyz/mud"},docsRepositoryBase:"https://github.com/latticexyz/mud/tree/main/docs",head:(0,o.jsx)(o.Fragment,{children:(0,o.jsx)("meta",{property:"title",content:"MUD documentation"})}),darkMode:!1,nextThemes:{defaultTheme:"dark"},footer:{text:"MIT 2023 \xa9 MUD"},primaryHue:28,sidebar:{defaultMenuCollapseLevel:1}};var t=n},2824:function(e,s,r){"use strict";var o=r(7505),l=r(6736),n=r(8823),t=r.n(n),i=r(2588);function a(e){let s=Object.assign({p:"p",ol:"ol",li:"li",code:"code",a:"a"},(0,l.ah)(),e.components);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.p,{children:(0,o.jsx)(t(),{alt:"Interaction between the World, a System, and a table",src:i.Z})}),"\n",(0,o.jsxs)(s.ol,{children:["\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["An account calls a function called ",(0,o.jsx)(s.code,{children:"game__myFunc"})," on the ",(0,o.jsx)(s.code,{children:"World"}),".\n",(0,o.jsx)(s.a,{href:"./function-selectors",children:"This function was registered"})," by the owner of the ",(0,o.jsx)(s.code,{children:"game"})," namespace and points to the ",(0,o.jsx)(s.code,{children:"myFunc"})," function in one of the ",(0,o.jsx)(s.code,{children:"System"}),"s in the ",(0,o.jsx)(s.code,{children:"namespace"})," namespace."]}),"\n"]}),"\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["The ",(0,o.jsx)(s.code,{children:"World"})," verifies that access is permitted (for example, because ",(0,o.jsx)(s.code,{children:"game:System"})," is publicly accessible) and if so calls ",(0,o.jsx)(s.code,{children:"myFunc"})," on the ",(0,o.jsx)(s.code,{children:"game:System"})," contract with the provided parameters."]}),"\n"]}),"\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["At some point in its execution ",(0,o.jsx)(s.code,{children:"myFunc"})," decides to update the data in the table ",(0,o.jsx)(s.code,{children:"game:Items"}),".\nAs with all other tables, this table is stored in the ",(0,o.jsx)(s.code,{children:"World"}),"'s storage.\nTo modify it, ",(0,o.jsx)(s.code,{children:"function"})," calls a function on the ",(0,o.jsx)(s.code,{children:"World"})," contract."]}),"\n"]}),"\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["The ",(0,o.jsx)(s.code,{children:"World"})," verifies that access is permitted (by default it would be, because ",(0,o.jsx)(s.code,{children:"game:System"})," has access to the ",(0,o.jsx)(s.code,{children:"game"})," namespace).\nIf so, it modifies the data in the ",(0,o.jsx)(s.code,{children:"game:Items"})," table."]}),"\n"]}),"\n"]})]})}s.Z=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}=Object.assign({},(0,l.ah)(),e.components);return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(a,{...e})}):a(e)}},9360:function(e,s,r){"use strict";r.r(s);var o=r(7505),l=r(2585),n=r(6252),t=r(3307);r(4693);var i=r(6736);r(8823);var a=r(8986),c=r(2824);let d={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:s}=Object.assign({},(0,i.ah)(),e.components);return s?(0,o.jsx)(s,{...e,children:(0,o.jsx)(h,{...e})}):h(e)},pageOpts:{filePath:"pages/world/tables.mdx",route:"/world/tables",headings:[{depth:1,value:"Tables",id:"tables"},{depth:2,value:"Code samples",id:"code-samples"},{depth:3,value:"Reading from a table",id:"reading-from-a-table"},{depth:3,value:"Writing to table",id:"writing-to-table"}],pageMap:[{kind:"Meta",data:{introduction:{title:"What is MUD?",theme:{breadcrumb:!1}},quickstart:{title:"Get started",theme:{breadcrumb:!1}},protocol:{title:"Protocol",type:"separator"},store:"Store",world:"World",framework:{title:"Framework",type:"separator"},config:"Config",cli:"CLI","state-query":"State Query",services:"Services","---":{title:"",type:"separator"},guides:"Guides",templates:"Templates",contribute:{title:"Contribute",theme:{breadcrumb:!1}},changelog:"Changelog",retrospectives:"Retrospectives",version:{title:"2.0.0-next.17",type:"menu",items:{changelog:{title:"Changelog",href:"/changelog"},contribute:{title:"Contribute",href:"/contribute"}}},status:{title:"Status",type:"page",href:"https://status.mud.dev",newWindow:!0},community:{title:"Community",type:"page",href:"https://community.mud.dev",newWindow:!0},twitter:{title:"Twitter",type:"page",href:"https://twitter.com/latticexyz",newWindow:!0},discord:{title:"Discord",type:"page",href:"https://lattice.xyz/discord",newWindow:!0}}},{kind:"MdxPage",name:"changelog",route:"/changelog"},{kind:"Folder",name:"cli",route:"/cli",children:[{kind:"Meta",data:{tablegen:"mud tablegen",worldgen:"mud worldgen",test:"mud test",deploy:"mud deploy","dev-contracts":"mud dev-contracts","abi-ts":"mud abi-ts",faucet:"mud faucet","set-version":"mud set-version"}},{kind:"MdxPage",name:"abi-ts",route:"/cli/abi-ts"},{kind:"MdxPage",name:"deploy",route:"/cli/deploy"},{kind:"MdxPage",name:"dev-contracts",route:"/cli/dev-contracts"},{kind:"MdxPage",name:"faucet",route:"/cli/faucet"},{kind:"MdxPage",name:"set-version",route:"/cli/set-version"},{kind:"MdxPage",name:"tablegen",route:"/cli/tablegen"},{kind:"MdxPage",name:"test",route:"/cli/test"},{kind:"MdxPage",name:"worldgen",route:"/cli/worldgen"}]},{kind:"MdxPage",name:"config",route:"/config"},{kind:"MdxPage",name:"contribute",route:"/contribute"},{kind:"Folder",name:"guides",route:"/guides",children:[{kind:"Meta",data:{"replicating-onchain-state":"Replicating onchain state","hello-world":"Hello World","extending-a-world":"Extending a World",emojimon:"Emojimon"}},{kind:"Folder",name:"emojimon",route:"/guides/emojimon",children:[{kind:"MdxPage",name:"1-preface-the-ecs-model",route:"/guides/emojimon/1-preface-the-ecs-model"},{kind:"MdxPage",name:"2-getting-started",route:"/guides/emojimon/2-getting-started"},{kind:"MdxPage",name:"3-players-and-movement",route:"/guides/emojimon/3-players-and-movement"},{kind:"MdxPage",name:"4-map-and-terrain",route:"/guides/emojimon/4-map-and-terrain"},{kind:"MdxPage",name:"5-a-wild-emojimon-appears",route:"/guides/emojimon/5-a-wild-emojimon-appears"},{kind:"MdxPage",name:"6-advanced",route:"/guides/emojimon/6-advanced"},{kind:"Meta",data:{"1-preface-the-ecs-model":"Preface: the ECS model","2-getting-started":"Getting started","3-players-and-movement":"Players and movement","4-map-and-terrain":"Map and terrain","5-a-wild-emojimon-appears":"A wild Emojimon appears","6-advanced":"Advanced features"}}]},{kind:"MdxPage",name:"emojimon",route:"/guides/emojimon"},{kind:"MdxPage",name:"extending-a-world",route:"/guides/extending-a-world"},{kind:"Folder",name:"hello-world",route:"/guides/hello-world",children:[{kind:"Meta",data:{"add-table":"Add a table","filter-sync":"Filter data synchronization","add-system":"Add a system",deploy:{title:"Deploy to a blockchain",href:"/cli/deploy"}}},{kind:"MdxPage",name:"add-system",route:"/guides/hello-world/add-system"},{kind:"MdxPage",name:"add-table",route:"/guides/hello-world/add-table"},{kind:"MdxPage",name:"filter-sync",route:"/guides/hello-world/filter-sync"}]},{kind:"MdxPage",name:"hello-world",route:"/guides/hello-world"},{kind:"MdxPage",name:"replicating-onchain-state",route:"/guides/replicating-onchain-state"}]},{kind:"MdxPage",name:"introduction",route:"/introduction"},{kind:"MdxPage",name:"quickstart",route:"/quickstart"},{kind:"Folder",name:"retrospectives",route:"/retrospectives",children:[{kind:"MdxPage",name:"2023-09-12-register-system-vulnerability",route:"/retrospectives/2023-09-12-register-system-vulnerability"},{kind:"Meta",data:{"2023-09-12-register-system-vulnerability":"2023-09-12 registerSystem vulnerability"}}]},{kind:"Folder",name:"services",route:"/services",children:[{kind:"Meta",data:{indexer:"Indexer",faucet:"Faucet"}},{kind:"MdxPage",name:"faucet",route:"/services/faucet"},{kind:"MdxPage",name:"indexer",route:"/services/indexer"}]},{kind:"Folder",name:"state-query",route:"/state-query",children:[{kind:"Meta",data:{typescript:"TypeScript"}},{kind:"Folder",name:"typescript",route:"/state-query/typescript",children:[{kind:"Meta",data:{recs:"RECS",zustand:"Zustand"}},{kind:"MdxPage",name:"recs",route:"/state-query/typescript/recs"},{kind:"MdxPage",name:"zustand",route:"/state-query/typescript/zustand"}]}]},{kind:"Folder",name:"store",route:"/store",children:[{kind:"Meta",data:{introduction:"Introduction","data-model":"Data model",tables:"Tables","table-libraries":"Table libraries",encoding:"Encoding","store-hooks":"Store hooks",reference:"Reference"}},{kind:"MdxPage",name:"data-model",route:"/store/data-model"},{kind:"MdxPage",name:"encoding",route:"/store/encoding"},{kind:"MdxPage",name:"introduction",route:"/store/introduction"},{kind:"Folder",name:"reference",route:"/store/reference",children:[{kind:"Meta",data:{"store-core":"StoreCore (internal)",store:"IStore (external)","store-hook":"StoreHook",misc:"Miscellaneous"}},{kind:"MdxPage",name:"misc",route:"/store/reference/misc"},{kind:"MdxPage",name:"store-core",route:"/store/reference/store-core"},{kind:"MdxPage",name:"store-hook",route:"/store/reference/store-hook"},{kind:"MdxPage",name:"store",route:"/store/reference/store"}]},{kind:"MdxPage",name:"store-hooks",route:"/store/store-hooks"},{kind:"MdxPage",name:"table-libraries",route:"/store/table-libraries"},{kind:"MdxPage",name:"tables",route:"/store/tables"}]},{kind:"Folder",name:"templates",route:"/templates",children:[{kind:"Meta",data:{typescript:"TypeScript",godot:"Godot",pwa:"Progressive Web App (for mobile)",swift:"Swift",svelte:"Svelte",unity:"Unity",disclaimer:{display:"hidden",title:"Disclaimer"}}},{kind:"MdxPage",name:"disclaimer",route:"/templates/disclaimer"},{kind:"MdxPage",name:"godot",route:"/templates/godot"},{kind:"MdxPage",name:"pwa",route:"/templates/pwa"},{kind:"MdxPage",name:"svelte",route:"/templates/svelte"},{kind:"MdxPage",name:"swift",route:"/templates/swift"},{kind:"Folder",name:"typescript",route:"/templates/typescript",children:[{kind:"Meta",data:{"getting-started":"Getting Started",contracts:"Contracts",vanilla:"Vanilla","react-ecs":"React-ECS",three:"Three.js"}},{kind:"MdxPage",name:"contracts",route:"/templates/typescript/contracts"},{kind:"MdxPage",name:"getting-started",route:"/templates/typescript/getting-started"},{kind:"MdxPage",name:"react-ecs",route:"/templates/typescript/react-ecs"},{kind:"MdxPage",name:"three",route:"/templates/typescript/three"},{kind:"MdxPage",name:"vanilla",route:"/templates/typescript/vanilla"}]},{kind:"MdxPage",name:"unity",route:"/templates/unity"}]},{kind:"Folder",name:"world",route:"/world",children:[{kind:"Meta",data:{introduction:"Introduction","namespaces-access-control":"Namespaces & Access Control",tables:"Tables",systems:"Systems","system-hooks":"System Hooks","function-selectors":"Function Selectors",balance:"Balance","account-delegation":"Account Delegation","batch-calls":"Batch Calls",modules:"Modules",reference:"Reference","world-table-illustration":{display:"hidden",title:"World Table Illustration"}}},{kind:"MdxPage",name:"account-delegation",route:"/world/account-delegation"},{kind:"MdxPage",name:"balance",route:"/world/balance"},{kind:"MdxPage",name:"batch-calls",route:"/world/batch-calls"},{kind:"MdxPage",name:"function-selectors",route:"/world/function-selectors"},{kind:"MdxPage",name:"introduction",route:"/world/introduction"},{kind:"Folder",name:"modules",route:"/world/modules",children:[{kind:"Meta",data:{keyswithvalue:"Keys with Value"}},{kind:"MdxPage",name:"keyswithvalue",route:"/world/modules/keyswithvalue"}]},{kind:"MdxPage",name:"modules",route:"/world/modules"},{kind:"MdxPage",name:"namespaces-access-control",route:"/world/namespaces-access-control"},{kind:"Folder",name:"reference",route:"/world/reference",children:[{kind:"Meta",data:{"delegation-external":"Delegation (interface)",module:"Modules","module-external":"Modules (interface)",system:"Systems","system-external":"Systems (interface)",world:"World","world-external":"World (interfaces)","world-context":"World context","world-context-external":"World context (interface)","resource-ids":"Resource IDs",misc:"Miscellaneous",internal:"Internals"}},{kind:"MdxPage",name:"delegation-external",route:"/world/reference/delegation-external"},{kind:"Folder",name:"internal",route:"/world/reference/internal",children:[{kind:"Meta",data:{"access-control":"Access Control",create:"Create2",delegation:"Delegation",erc165:"ERC165","erc165-external":"ERC165 (interface)","init-module":"Init Module","init-module-implementation":"Init Module Implementation",systemcall:"SystemCall"}},{kind:"MdxPage",name:"access-control",route:"/world/reference/internal/access-control"},{kind:"MdxPage",name:"create",route:"/world/reference/internal/create"},{kind:"MdxPage",name:"delegation",route:"/world/reference/internal/delegation"},{kind:"MdxPage",name:"erc165-external",route:"/world/reference/internal/erc165-external"},{kind:"MdxPage",name:"erc165",route:"/world/reference/internal/erc165"},{kind:"MdxPage",name:"init-module-implementation",route:"/world/reference/internal/init-module-implementation"},{kind:"MdxPage",name:"init-module",route:"/world/reference/internal/init-module"},{kind:"MdxPage",name:"systemcall",route:"/world/reference/internal/systemcall"}]},{kind:"MdxPage",name:"misc",route:"/world/reference/misc"},{kind:"MdxPage",name:"module-external",route:"/world/reference/module-external"},{kind:"MdxPage",name:"module",route:"/world/reference/module"},{kind:"MdxPage",name:"resource-ids",route:"/world/reference/resource-ids"},{kind:"MdxPage",name:"system-external",route:"/world/reference/system-external"},{kind:"MdxPage",name:"system",route:"/world/reference/system"},{kind:"MdxPage",name:"world-context-external",route:"/world/reference/world-context-external"},{kind:"MdxPage",name:"world-context",route:"/world/reference/world-context"},{kind:"MdxPage",name:"world-external",route:"/world/reference/world-external"},{kind:"MdxPage",name:"world",route:"/world/reference/world"}]},{kind:"MdxPage",name:"system-hooks",route:"/world/system-hooks"},{kind:"MdxPage",name:"systems",route:"/world/systems"},{kind:"MdxPage",name:"tables",route:"/world/tables"},{kind:"MdxPage",name:"world-table-illustration",route:"/world/world-table-illustration"}]}],flexsearch:{codeblocks:!0},title:"Tables"},pageNextRoute:"/world/tables",nextraLayout:n.ZP,themeConfig:t.Z};function h(e){let s=Object.assign({h1:"h1",p:"p",code:"code",a:"a",ul:"ul",li:"li",h2:"h2",h3:"h3",pre:"pre",span:"span",details:"details",summary:"summary"},(0,i.ah)(),e.components);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(s.h1,{children:"Tables"}),"\n",(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:"World"})," uses the ",(0,o.jsx)(s.a,{href:"/store/tables",children:"store tables"}),", but adds ",(0,o.jsx)(s.a,{href:"/world/namespaces-access-control",children:"access control"}),".\nFor onchain tables, the data is stored by the ",(0,o.jsx)(s.code,{children:"World"})," contract, ",(0,o.jsxs)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol#L43",children:["which is also a ",(0,o.jsx)(s.code,{children:"StoreData"})]}),"."]}),"\n",(0,o.jsxs)(s.p,{children:["When a ",(0,o.jsx)(s.code,{children:"System"})," reads or writes storage via ",(0,o.jsx)(s.a,{href:"/store/table-libraries",children:"table libraries"}),", the request goes into ",(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreSwitch.sol",children:(0,o.jsx)(s.code,{children:"StoreSwitch"})}),". This library decides which approach to use:"]}),"\n",(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["If the ",(0,o.jsx)(s.code,{children:"System"})," is in the root namespace, then it was called with ",(0,o.jsx)(s.a,{href:"https://docs.soliditylang.org/en/v0.8.22/introduction-to-smart-contracts.html#delegatecall-and-libraries",children:(0,o.jsx)(s.code,{children:"delegatecall"})}),".\nThis means it inherits the ",(0,o.jsx)(s.code,{children:"World"})," storage and can write directly to storage using ",(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreCore.sol",children:(0,o.jsx)(s.code,{children:"StoreCore"})}),".\nThese calls bypass access control."]}),"\n"]}),"\n",(0,o.jsxs)(s.li,{children:["\n",(0,o.jsxs)(s.p,{children:["If the ",(0,o.jsx)(s.code,{children:"System"})," is in any other namespace, then it was called with ",(0,o.jsx)(s.a,{href:"https://docs.soliditylang.org/en/v0.8.22/introduction-to-smart-contracts.html#message-calls",children:(0,o.jsx)(s.code,{children:"call"})})," and has to call back into the ",(0,o.jsx)(s.code,{children:"World"})," using ",(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/IStore.sol",children:(0,o.jsx)(s.code,{children:"IStore"})}),".\nThese calls go through access control.\nThey are only permitted if the ",(0,o.jsx)(s.code,{children:"System"})," has access to the table in question.\nBy default a ",(0,o.jsx)(s.code,{children:"System"})," has access to its own namespace and therefore to all the tables inside it.\nAdditional ",(0,o.jsx)(s.a,{href:"./namespaces-access-control",children:"access can be granted"})," by the namespace owner."]}),"\n"]}),"\n"]}),"\n",(0,o.jsx)(c.Z,{}),"\n",(0,o.jsx)(s.h2,{id:"code-samples",children:"Code samples"}),"\n",(0,o.jsx)(s.h3,{id:"reading-from-a-table",children:"Reading from a table"}),"\n",(0,o.jsxs)(s.p,{children:["Anybody connected to the blockchain can run the ",(0,o.jsx)(s.code,{children:"view"})," functions that read table content."]}),"\n",(0,o.jsx)(a.C,{children:(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",filename:"ReadTableInformation.s.sol",hasCopyCode:!0,children:(0,o.jsxs)(s.code,{"data-line-numbers":"","data-language":"solidity","data-theme":"default","data-line-numbers-max-digits":"2",children:[(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// SPDX-License-Identifier: MIT"})}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"pragma"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"solidity"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" >=0.8.21;"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"forge-std/Script.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"console"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"forge-std/console.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"StoreSwitch"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/StoreSwitch.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsx)(s.span,{className:"line highlighted",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Read and manipulate the Systems table"})}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Systems"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:", "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"SystemsTableId"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/codegen/index.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsx)(s.span,{className:"line highlighted",children:" "}),"\n",(0,o.jsx)(s.span,{className:"line highlighted",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// The key is a ResourceId"})}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"ResourceId"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/ResourceId.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"RESOURCE_SYSTEM"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/worldResourceTypes.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"WorldResourceIdLib"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/WorldResourceId.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"contract"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"ReadTableInformation"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"is"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"run"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"() "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"external"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Load the world address and specify it as the Store address"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" worldAddress "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"envAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"WORLD_ADDRESS"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    StoreSwitch."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"setStoreAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Table metainformation (field names)"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"string"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyNames "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"getKeyNames"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"string"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" valueNames "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"getFieldNames"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Key fields:"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"for"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" i "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"0"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"; i "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"<"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyNames.length; i"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"++"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"\\t"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" i"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyNames[i]);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    }"})}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Value fields:"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"for"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" ("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" i "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"0"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"; i "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"<"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" valueNames.length; i"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"++"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:") {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"\\t"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" i"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" valueNames[i]);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    }"})}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Read information about the :AccessManagement System"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    ResourceId accessManagementSystem "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" WorldResourceIdLib."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"encode"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      RESOURCE_SYSTEM"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// System"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'""'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Root namespace"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"AccessManagement"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Called AccessManagement"})]}),"\n",(0,o.jsx)(s.span,{className:"line highlighted",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    );"})}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    ("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" systemAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bool"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" publicAccess) "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"get"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(accessManagementSystem);"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"The address for the :AccessManagement System:"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" systemAddress);"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    console."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"log"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Public access:"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" publicAccess);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  }"})}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})})}),"\n",(0,o.jsxs)(s.details,{children:[(0,o.jsx)(s.summary,{children:"Explanation"}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsx)(s.code,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"StoreSwitch"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/StoreSwitch.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})})}),(0,o.jsxs)(s.p,{children:["We need ",(0,o.jsxs)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreSwitch.sol",children:["the ",(0,o.jsx)(s.code,{children:"StoreSwitch"})," library"]})," library to specify the address of the ",(0,o.jsx)(s.code,{children:"World"})," with the data."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Read and manipulate the Systems table"})}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Systems"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:", "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"SystemsTableId"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/codegen/index.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})]})}),(0,o.jsxs)(s.p,{children:["It is easiest if we import the definitions of the table that were generated using ",(0,o.jsx)(s.a,{href:"./cli/tablegen",children:(0,o.jsx)(s.code,{children:"mud tablegen"})}),"."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// The key is a ResourceId"})}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"ResourceId"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/ResourceId.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"RESOURCE_SYSTEM"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/worldResourceTypes.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"WorldResourceIdLib"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/world/src/WorldResourceId.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})]})}),(0,o.jsxs)(s.p,{children:["The key of the ",(0,o.jsx)(s.code,{children:"store:Tables"})," table is the resource ID for the various tables.\nTo read the information of a specific table later we need to create the appropriate resource ID."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"contract"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"ReadTableInformation"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"is"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"run"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"() "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"external"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Load the world address and specify it as the Store address"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" worldAddress "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"envAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"WORLD_ADDRESS"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    StoreSwitch."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"setStoreAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress);"})]})]})}),(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreSwitch.sol#L58-L65",children:(0,o.jsx)(s.code,{children:"StoreSwitch.setStoreAddress"})})," is the function we call to specify the ",(0,o.jsx)(s.code,{children:"World"}),"'s address."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Table metainformation (field names)"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"string"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" keyNames "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"getKeyNames"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"string"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"[] "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"memory"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" valueNames "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"getFieldNames"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]})]})}),(0,o.jsx)(s.p,{children:"These functions give us the names of the key fields and value field."}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Read information about the :AccessManagement System"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    ResourceId accessManagementSystem "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" WorldResourceIdLib."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"encode"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      RESOURCE_SYSTEM"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"     "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// System"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'""'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"                  "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Root namespace"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"      "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"AccessManagement"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"   "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Called AccessManagement"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    );"})})]})}),(0,o.jsx)(s.p,{children:"Here we create the resource ID for the table whose information we want."}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsx)(s.code,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    ("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" systemAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bool"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" publicAccess) "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" Systems."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"get"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(accessManagementSystem);"})]})})}),(0,o.jsx)(s.p,{children:"And actually read the information."})]}),"\n",(0,o.jsx)(s.h3,{id:"writing-to-table",children:"Writing to table"}),"\n",(0,o.jsxs)(s.p,{children:["This code is taken from ",(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/tree/main/templates/react",children:"the React template"}),".\nNote that only ",(0,o.jsx)(s.a,{href:"/world/namespaces-access-control#access",children:"authorized addresses"})," are allowed to write directly to a table."]}),"\n",(0,o.jsx)(a.C,{children:(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",filename:"PostDeploy.s.sol",hasCopyCode:!0,children:(0,o.jsxs)(s.code,{"data-line-numbers":"","data-language":"solidity","data-theme":"default","data-line-numbers-max-digits":"2",children:[(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// SPDX-License-Identifier: MIT"})}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"pragma"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:"solidity"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" >=0.8.24;"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"forge-std/Script.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"console"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"forge-std/console.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"StoreSwitch"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/StoreSwitch.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"IWorld"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"../src/codegen/world/IWorld.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Tasks"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:", "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"TasksData"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"../src/codegen/index.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"contract"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"PostDeploy"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"is"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"run"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" worldAddress) "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"external"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Specify a store so that you can use tables directly in PostDeploy"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    StoreSwitch."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"setStoreAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Load the private key from the `PRIVATE_KEY` environment variable (in .env)"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"uint256"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" deployerPrivateKey "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"envUint"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"PRIVATE_KEY"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Start broadcasting transactions from the deployer account"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"startBroadcast"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(deployerPrivateKey);"})]}),"\n",(0,o.jsx)(s.span,{className:"line highlighted",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// We can set table records directly"})]}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    Tasks."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"set"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"1"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"TasksData"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"({ description"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Walk the dog"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" createdAt"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" block.timestamp"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" completedAt"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"0"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" }));"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Or we can call our own systems"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"IWorld"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress)."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"addTask"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Take out the trash"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"bytes32"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" key "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"IWorld"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress)."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"addTask"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Do the dishes"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:");"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"IWorld"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress)."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"completeTask"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(key);"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line highlighted",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"stopBroadcast"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  }"})}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})})}),"\n",(0,o.jsxs)(s.details,{children:[(0,o.jsx)(s.summary,{children:"Explanation"}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsx)(s.code,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"StoreSwitch"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"@latticexyz/store/src/StoreSwitch.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})})}),(0,o.jsxs)(s.p,{children:["We need ",(0,o.jsxs)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreSwitch.sol",children:["the ",(0,o.jsx)(s.code,{children:"StoreSwitch"})," library"]})," library to specify the address of the ",(0,o.jsx)(s.code,{children:"World"})," with the data."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsx)(s.code,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"import"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" { "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Tasks"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:", "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"TasksData"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" } "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"from"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"../src/codegen/index.sol"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})})}),(0,o.jsxs)(s.p,{children:["It is easiest if we import the definitions of the table that were generated using ",(0,o.jsx)(s.a,{href:"./cli/tablegen",children:(0,o.jsx)(s.code,{children:"mud tablegen"})}),"."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"contract"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"PostDeploy"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"is"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"Script"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"function"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"run"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"address"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" worldAddress) "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:"external"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" {"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Specify a store so that you can use tables directly in PostDeploy"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    StoreSwitch."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"setStoreAddress"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(worldAddress);"})]})]})}),(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.a,{href:"https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreSwitch.sol#L58-L65",children:(0,o.jsx)(s.code,{children:"StoreSwitch.setStoreAddress"})})," is the function we call to specify the ",(0,o.jsx)(s.code,{children:"World"}),"'s address."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// Start broadcasting transactions from the deployer account"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"startBroadcast"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"(deployerPrivateKey);"})]})]})}),(0,o.jsxs)(s.p,{children:[(0,o.jsx)(s.code,{children:".set"})," changes the state of the blockchain, so it requires an address.\nThis address is necessary for two reasons:"]}),(0,o.jsxs)(s.ul,{children:["\n",(0,o.jsx)(s.li,{children:"To spend ETH for gas."}),"\n",(0,o.jsxs)(s.li,{children:["To ",(0,o.jsx)(s.a,{href:"./namespaces-access-control#access",children:"check permissions"}),"."]}),"\n"]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsx)(s.span,{className:"line",children:" "}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-comment)"},children:"// We can set table records directly"})]}),"\n",(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    Tasks."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"set"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"("}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"1"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"TasksData"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"({ description"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"Walk the dog"'}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" createdAt"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" block.timestamp"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-punctuation)"},children:","}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" completedAt"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-keyword)"},children:":"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-constant)"},children:"0"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:" }));"})]})]})}),(0,o.jsxs)(s.p,{children:["Create a new ",(0,o.jsx)(s.code,{children:"TasksData"})," and set that value with the key ",(0,o.jsx)(s.code,{children:'"1"'})," (in hex the key is ",(0,o.jsx)(s.code,{children:"0x310...0"}),")."]}),(0,o.jsx)(s.pre,{"data-language":"solidity","data-theme":"default",children:(0,o.jsxs)(s.code,{"data-language":"solidity","data-theme":"default",children:[(0,o.jsxs)(s.span,{className:"line",children:[(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"    vm."}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-token-function)"},children:"stopBroadcast"}),(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"();"})]}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"  }"})}),"\n",(0,o.jsx)(s.span,{className:"line",children:(0,o.jsx)(s.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),(0,o.jsx)(s.p,{children:"Stop broadcasting transactions as the authorized address."})]})]})}s.default=(0,l.j)(d)},4737:function(e){e.exports={collapsed:"CollapseCode_collapsed__D1CXB",expanded:"CollapseCode_expanded__x1xKU"}}},function(e){e.O(0,[1877,2888,179],function(){return e(e.s=1683)}),_N_E=e.O()}]);