(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6261],{96612:function(e,n,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/indexer/postgres-event-only",function(){return t(84206)}])},48986:function(e,n,t){"use strict";t.d(n,{C:function(){return o}});var s=t(7505),r=t(7765),i=t(24737),a=t.n(i);function o(e){let{children:n}=e,t=(0,r.useRef)(null),[i,o]=(0,r.useState)(!0);return(0,r.useEffect)(()=>{if(!t.current)return;let e=Array.from(t.current.querySelectorAll(".line")),n=[];e.forEach((e,t)=>{e.matches(".highlighted")&&n.push(t),/^\s+$/g.test(e.innerHTML)&&e.setAttribute("data-empty","")}),n.length&&e.forEach((e,t)=>{let s=n.reduce((e,n)=>Math.min(e,Math.abs(n-t)),1/0);e.setAttribute("data-highlight-distance",Math.min(s,4).toString())})},[i]),(0,s.jsx)("div",{ref:t,style:{marginTop:"1.5rem"},className:i?a().collapsed:a().expanded,onClick:e=>{e.target instanceof Element&&e.target.closest(".line")&&o(!i)},children:n})}},73307:function(e,n,t){"use strict";t.d(n,{Z:function(){return a}});var s=t(7505),r=t(11689);let i={logo:function(){return(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.25em",fontSize:"32px",fontFamily:"PP Supply Mono",textTransform:"uppercase"},children:[(0,s.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,r.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,s.jsx)(s.Fragment,{children:(0,s.jsx)("meta",{property:"title",content:"MUD documentation"})}),darkMode:!1,nextThemes:{defaultTheme:"dark"},footer:{text:"MIT 2023 \xa9 MUD"},primaryHue:28,sidebar:{defaultMenuCollapseLevel:1}};var a=i},84206:function(e,n,t){"use strict";t.r(n);var s=t(7505),r=t(42585),i=t(38288),a=t(73307);t(54693);var o=t(26736);t(98823),t(64738),t(48986);let l={MDXContent:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{wrapper:n}=Object.assign({},(0,o.ah)(),e.components);return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)},pageOpts:{filePath:"pages/indexer/postgres-event-only.mdx",route:"/indexer/postgres-event-only",headings:[{depth:1,value:"Postgres for Events Only",id:"postgres-for-events-only"},{depth:2,value:"Installation",id:"installation"},{depth:3,value:"Environment variables",id:"environment-variables"},{depth:3,value:"Using npx",id:"using-npx"},{depth:3,value:"Docker",id:"docker"},{depth:2,value:"Using the indexer",id:"using-the-indexer"},{depth:3,value:"Viewing events",id:"viewing-events"},{depth:3,value:"Clearing the information",id:"clearing-the-information"}],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",indexer:"Indexer","world-explorer":{title:"World Explorer",theme:{breadcrumb:!1}},"---":{title:"",type:"separator"},guides:"Guides",templates:"Templates","best-practices":"Best Practices",contribute:{title:"Contribute",theme:{breadcrumb:!1}},changelog:"Changelog",retrospectives:"Retrospectives",audits:"Audits",version:{title:"2.2.9",type:"menu",items:{changelog:{title:"Changelog",href:"/changelog"},contribute:{title:"Contribute",href:"/contribute"}}},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:"Folder",name:"audits",route:"/audits",children:[{kind:"MdxPage",name:"2024-02-11-open-zeppelin",route:"/audits/2024-02-11-open-zeppelin"},{kind:"Meta",data:{"2024-02-11-open-zeppelin":"2024-02-11 OpenZeppelin",pdf:{display:"hidden"},icons:{display:"hidden"}}}]},{kind:"Folder",name:"best-practices",route:"/best-practices",children:[{kind:"Meta",data:{"dividing-into-systems":"Dividing Code into Systems",system:"System Best Practices","deployment-settings":"Recommended Deployment Settings","aws-kms":"Deploy production worlds using AWS KMS"}},{kind:"MdxPage",name:"aws-kms",route:"/best-practices/aws-kms"},{kind:"MdxPage",name:"deployment-settings",route:"/best-practices/deployment-settings"},{kind:"MdxPage",name:"dividing-into-systems",route:"/best-practices/dividing-into-systems"},{kind:"MdxPage",name:"system",route:"/best-practices/system"}]},{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",verify:"mud verify","dev-contracts":"mud dev-contracts","abi-ts":"mud abi-ts","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:"set-version",route:"/cli/set-version"},{kind:"MdxPage",name:"tablegen",route:"/cli/tablegen"},{kind:"MdxPage",name:"test",route:"/cli/test"},{kind:"MdxPage",name:"verify",route:"/cli/verify"},{kind:"MdxPage",name:"worldgen",route:"/cli/worldgen"}]},{kind:"Folder",name:"config",route:"/config",children:[{kind:"MdxPage",name:"reference",route:"/config/reference"},{kind:"Meta",data:{reference:"Reference"}}]},{kind:"MdxPage",name:"config",route:"/config"},{kind:"MdxPage",name:"contribute",route:"/contribute"},{kind:"Folder",name:"guides",route:"/guides",children:[{kind:"Meta",data:{"hello-world":"Hello World","extending-a-world":"Extending a World","adding-delegation":"Adding Delegation",modules:"Writing MUD Modules",emojimon:"Emojimon",testing:"Testing","replicating-onchain-state":"Replicating onchain state"}},{kind:"MdxPage",name:"adding-delegation",route:"/guides/adding-delegation"},{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:"Folder",name:"extending-a-world",route:"/guides/extending-a-world",children:[{kind:"Meta",data:{index:"Extending a World Permissionlessly"}},{kind:"MdxPage",name:"index",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:"Deploy to a blockchain","add-chain-client":"Add chains to the client"}},{kind:"MdxPage",name:"add-chain-client",route:"/guides/hello-world/add-chain-client"},{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:"deploy",route:"/guides/hello-world/deploy"},{kind:"MdxPage",name:"filter-sync",route:"/guides/hello-world/filter-sync"}]},{kind:"MdxPage",name:"hello-world",route:"/guides/hello-world"},{kind:"MdxPage",name:"modules",route:"/guides/modules"},{kind:"MdxPage",name:"replicating-onchain-state",route:"/guides/replicating-onchain-state"},{kind:"MdxPage",name:"testing",route:"/guides/testing"}]},{kind:"Folder",name:"indexer",route:"/indexer",children:[{kind:"Meta",data:{using:"Using the Indexer",sqlite:"SQLite Indexer","postgres-event-only":"PostgreSQL for events","postgres-decoded":"PostgreSQL for data (and events)",sql:"SQL API (Experimental)"}},{kind:"MdxPage",name:"postgres-decoded",route:"/indexer/postgres-decoded"},{kind:"MdxPage",name:"postgres-event-only",route:"/indexer/postgres-event-only"},{kind:"MdxPage",name:"sql",route:"/indexer/sql"},{kind:"MdxPage",name:"sqlite",route:"/indexer/sqlite"},{kind:"MdxPage",name:"using",route:"/indexer/using"}]},{kind:"MdxPage",name:"indexer",route:"/indexer"},{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:"MdxPage",name:"2024-04-17-storeread-getdynamicfieldlength-bug",route:"/retrospectives/2024-04-17-storeread-getdynamicfieldlength-bug"},{kind:"Meta",data:{"2024-04-17-storeread-getdynamicfieldlength-bug":"2024-04-17 StoreRead.getDynamicFieldLength bug","2023-09-12-register-system-vulnerability":"2023-09-12 registerSystem vulnerability"}}]},{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",nethereum:"Nethereum"}},{kind:"MdxPage",name:"godot",route:"/templates/godot"},{kind:"MdxPage",name:"nethereum",route:"/templates/nethereum"},{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:{contracts:"Contracts",vanilla:"Vanilla","react-ecs":"React-ECS",threejs:"Three.js",vue:"Vue"}},{kind:"MdxPage",name:"contracts",route:"/templates/typescript/contracts"},{kind:"MdxPage",name:"react-ecs",route:"/templates/typescript/react-ecs"},{kind:"MdxPage",name:"threejs",route:"/templates/typescript/threejs"},{kind:"MdxPage",name:"vanilla",route:"/templates/typescript/vanilla"},{kind:"MdxPage",name:"vue",route:"/templates/typescript/vue"}]},{kind:"MdxPage",name:"unity",route:"/templates/unity"}]},{kind:"MdxPage",name:"templates",route:"/templates"},{kind:"Folder",name:"world",route:"/world",children:[{kind:"Meta",data:{introduction:"Introduction","resource-ids":"Resource Identifiers","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",upgrades:"Upgrading",modules:"Modules",reference:"Reference"}},{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",keysintable:"Keys in Table",erc20:"ERC-20 tokens",erc721:"ERC-721 (NFT)"}},{kind:"MdxPage",name:"erc20",route:"/world/modules/erc20"},{kind:"MdxPage",name:"erc721",route:"/world/modules/erc721"},{kind:"MdxPage",name:"keysintable",route:"/world/modules/keysintable"},{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:"resource-ids",route:"/world/resource-ids"},{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:"upgrades",route:"/world/upgrades"}]},{kind:"MdxPage",name:"world-explorer",route:"/world-explorer"}],flexsearch:{codeblocks:!0},title:"Postgres for Events Only"},pageNextRoute:"/indexer/postgres-event-only",nextraLayout:i.ZP,themeConfig:a.Z};function d(e){let n=Object.assign({h1:"h1",h2:"h2",h3:"h3",p:"p",table:"table",thead:"thead",tr:"tr",th:"th",code:"code",tbody:"tbody",td:"td",a:"a",ol:"ol",li:"li",pre:"pre",span:"span",ul:"ul",strong:"strong",details:"details",summary:"summary"},(0,o.ah)(),e.components);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.h1,{children:"Postgres for Events Only"}),"\n",(0,s.jsx)(n.h2,{id:"installation",children:"Installation"}),"\n",(0,s.jsx)(n.h3,{id:"environment-variables",children:"Environment variables"}),"\n",(0,s.jsx)(n.p,{children:"These environment variables need to be provided to the indexer to work:"}),"\n",(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Type"}),(0,s.jsx)(n.th,{children:"Variable"}),(0,s.jsx)(n.th,{children:"Meaning"}),(0,s.jsxs)(n.th,{children:["Sample value (using ",(0,s.jsx)(n.code,{children:"anvil"})," running on the host)"]})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Required"}),(0,s.jsx)(n.td,{children:"RPC_HTTP_URL"}),(0,s.jsx)(n.td,{children:"The URL to access the blockchain using HTTP"}),(0,s.jsxs)(n.td,{children:[(0,s.jsx)(n.a,{href:"http://host.docker.internal:8545",children:"http://host.docker.internal:8545"})," (when running in Docker)"]})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Optional"}),(0,s.jsx)(n.td,{children:"RPC_WS_URL"}),(0,s.jsx)(n.td,{children:"The URL to access the blockchain using WebSocket"}),(0,s.jsx)(n.td,{})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Optional"}),(0,s.jsx)(n.td,{children:"START_BLOCK"}),(0,s.jsxs)(n.td,{children:["The block to start indexing from. The block in which the ",(0,s.jsx)(n.code,{children:"World"})," contract was deployed is a good choice."]}),(0,s.jsx)(n.td,{children:"1"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Optional"}),(0,s.jsx)(n.td,{children:"DEBUG=mud:*"}),(0,s.jsx)(n.td,{children:"Turn on debugging"}),(0,s.jsx)(n.td,{})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Optional"}),(0,s.jsx)(n.td,{children:"STORE_ADDRESS"}),(0,s.jsxs)(n.td,{children:["Only index tables from this ",(0,s.jsx)(n.code,{children:"World"})]}),(0,s.jsx)(n.td,{})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Required"}),(0,s.jsx)(n.td,{children:"DATABASE_URL"}),(0,s.jsxs)(n.td,{children:["URL for the database, of the form ",(0,s.jsx)(n.code,{children:"postgres://<host>/<database>"})]}),(0,s.jsx)(n.td,{})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Optional"}),(0,s.jsx)(n.td,{children:"PORT"}),(0,s.jsx)(n.td,{children:"The port on which the indexer listens"}),(0,s.jsxs)(n.td,{children:[(0,s.jsx)(n.code,{children:"3001"})," (the default)"]})]})]})]}),"\n",(0,s.jsx)(n.h3,{id:"using-npx",children:"Using npx"}),"\n",(0,s.jsx)(n.p,{children:"The schemaless indexer stores MUD event records into a single monolithic table.\nThe main purpose of this variant of the indexer is to efficiently hydrate a MUD client, which decodes the data from the events."}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Start a ",(0,s.jsx)(n.code,{children:"World"})," to index.\nAn easy way to do this is to ",(0,s.jsx)(n.a,{href:"/templates/typescript/getting-started",children:"use a TypeScript template"})," in a separate command line window."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"Set the environment variables."}),"\n",(0,s.jsx)(n.pre,{"data-language":"bash","data-theme":"default",hasCopyCode:!0,children:(0,s.jsxs)(n.code,{"data-language":"bash","data-theme":"default",children:[(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" RPC_HTTP_URL"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"http://127.0.0.1:8545"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" DATABASE_URL"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"postgres://127.0.0.1/postgres"})]})]})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"Run the indexer.\nInstall it first if necessary."}),"\n",(0,s.jsx)(n.pre,{"data-language":"bash","data-theme":"default",hasCopyCode:!0,children:(0,s.jsx)(n.code,{"data-language":"bash","data-theme":"default",children:(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-y"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-p"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"@latticexyz/store-indexer"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"postgres-indexer"})]})})}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsx)(n.p,{children:"Open a separate command line.\nIn it, specify the database and run the indexer frontend, which is responsible for serving the data to the client."}),"\n",(0,s.jsx)(n.pre,{"data-language":"bash","data-theme":"default",hasCopyCode:!0,children:(0,s.jsxs)(n.code,{"data-language":"bash","data-theme":"default",children:[(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"export"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" DATABASE_URL"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"postgres://127.0.0.1/postgres"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"npx"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-y"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-p"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"@latticexyz/store-indexer"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"postgres-frontend"})]})]})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"docker",children:"Docker"}),"\n",(0,s.jsxs)(n.p,{children:["The indexer Docker image is available ",(0,s.jsx)(n.a,{href:"https://github.com/latticexyz/mud/pkgs/container/store-indexer",children:"on github"}),"."]}),"\n",(0,s.jsxs)(n.p,{children:["There are several ways to provide the environment variables to ",(0,s.jsx)(n.code,{children:"docker run"}),":"]}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsxs)(n.li,{children:["On the command line you can specify ",(0,s.jsx)(n.code,{children:"-e <variable>=<value>"}),".\nYou specify this after the ",(0,s.jsx)(n.code,{children:"docker run"}),", but before the name of the image."]}),"\n",(0,s.jsxs)(n.li,{children:["You can also write all the environment variables in a file and specify it using ",(0,s.jsx)(n.code,{children:"--env-file"}),".\nYou specify this after the ",(0,s.jsx)(n.code,{children:"docker run"}),", but before the name of the image."]}),"\n",(0,s.jsxs)(n.li,{children:["Both ",(0,s.jsx)(n.a,{href:"https://docs.docker.com/compose/",children:"Docker Compose"})," and ",(0,s.jsx)(n.a,{href:"https://kubernetes.io/",children:"Kubernetes"})," have their own mechanisms for starting docker containers with environment variables."]}),"\n"]}),"\n",(0,s.jsxs)(n.p,{children:["The easiest way to test the indexer is to ",(0,s.jsx)(n.a,{href:"/templates/typescript/getting-started",children:"run the template as a world"})," in a separate command-line window."]}),"\n",(0,s.jsxs)(n.p,{children:["The command to start the indexer in event-only PostgreSQL mode is ",(0,s.jsx)(n.code,{children:"pnpm start:postgres"}),".\nThis command starts both the indexer and query frontends."]}),"\n",(0,s.jsxs)(n.ol,{children:["\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["The docker instance identifies itself to PostgreSQL as ",(0,s.jsx)(n.code,{children:"root"}),".\nTo give this user permissions on the database, enter ",(0,s.jsx)(n.code,{children:"psql"})," and run this command."]}),"\n",(0,s.jsx)(n.pre,{"data-language":"sql","data-theme":"default",hasCopyCode:!0,children:(0,s.jsx)(n.code,{"data-language":"sql","data-theme":"default",children:(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"CREATE"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"ROLE"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"root"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" SUPERUSER "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"LOGIN"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:";"})]})})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Note:"})," This is assuming a database that is isolated from the internet and only used by trusted entities.\nIn a production system you will use at least a password as authentication, and limit the user's authority."]}),"\n"]}),"\n",(0,s.jsxs)(n.li,{children:["\n",(0,s.jsxs)(n.p,{children:["Start the docker container.\nFor example, to index an ",(0,s.jsx)(n.code,{children:"anvil"})," instance running to the host to the database ",(0,s.jsx)(n.code,{children:"postgres"})," on the host, use."]}),"\n",(0,s.jsx)(n.pre,{"data-language":"sh","data-theme":"default",hasCopyCode:!0,children:(0,s.jsxs)(n.code,{"data-language":"sh","data-theme":"default",children:[(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"docker"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"run"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"--platform"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"linux/amd64"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-e"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"RPC_HTTP_URL=http://host.docker.internal:8545"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-e"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"DATABASE_URL=postgres://host.docker.internal/postgres"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-p"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-constant)"},children:"3001"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:":3001"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"ghcr.io/latticexyz/store-indexer:latest"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"pnpm"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"start:postgres"})]})]})}),"\n",(0,s.jsx)(n.p,{children:"If you want to create additional query frontends (for reliability and load balancing), use these commands:"}),"\n",(0,s.jsx)(n.pre,{"data-language":"sh","data-theme":"default",hasCopyCode:!0,children:(0,s.jsxs)(n.code,{"data-language":"sh","data-theme":"default",children:[(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"HOST_PORT"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"="}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-constant)"},children:"3002"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"docker"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"run"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"--platform"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"linux/amd64"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-e"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"DATABASE_URL=postgres://host.docker.internal/postgres"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"-p"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" $HOST_PORT"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:":3001"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"ghcr.io/latticexyz/store-indexer:latest"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  \\"})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"node"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string)"},children:"dist/bin/postgres-frontend.js"})]})]})}),"\n"]}),"\n"]}),"\n",(0,s.jsx)(n.h2,{id:"using-the-indexer",children:"Using the indexer"}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.a,{href:"using-indexer",children:"See here how to use the indexer with a MUD client"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"viewing-events",children:"Viewing events"}),"\n",(0,s.jsx)(n.p,{children:"You can run this command to verify the indexer is working correctly."}),"\n",(0,s.jsx)(n.pre,{"data-language":"sh","data-theme":"default",hasCopyCode:!0,children:(0,s.jsx)(n.code,{"data-language":"sh","data-theme":"default",children:(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"curl"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string-expression)"},children:"'http://localhost:3001/api/logs?input=%7B%22chainId%22%3A31337%2C%22address%22%3A%220x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b%22%2C%22filters%22%3A%5B%5D%7D'"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"|"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-function)"},children:"jq"})]})})}),"\n",(0,s.jsxs)(n.p,{children:["The result should be nicely formatted (and long) JSON output with all the data change events that happened in that ",(0,s.jsx)(n.code,{children:"World"}),"."]}),"\n",(0,s.jsxs)(n.details,{children:[(0,s.jsx)(n.summary,{children:"Where does this URL come from?"}),(0,s.jsx)(n.p,{children:"The URL has these parameters:"}),(0,s.jsxs)(n.table,{children:[(0,s.jsx)(n.thead,{children:(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.th,{children:"Parameter"}),(0,s.jsx)(n.th,{children:"Value"}),(0,s.jsx)(n.th,{children:"Explanation"})]})}),(0,s.jsxs)(n.tbody,{children:[(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Server"}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.a,{href:"http://localhost:3001",children:"http://localhost:3001"})}),(0,s.jsx)(n.td,{children:"By default the indexer listens on port 3001"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:"Path"}),(0,s.jsx)(n.td,{children:"/api/logs"}),(0,s.jsx)(n.td,{children:"Read log events"})]}),(0,s.jsxs)(n.tr,{children:[(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"input"})}),(0,s.jsx)(n.td,{children:(0,s.jsx)(n.code,{children:"%7B%22 ... %5D%7D"})}),(0,s.jsx)(n.td,{children:"See below"})]})]})]}),(0,s.jsxs)(n.p,{children:["The input is the JSON filter that tells the server what we need.\nIt is ",(0,s.jsx)(n.a,{href:"https://en.wikipedia.org/wiki/Percent-encoding",children:"URL encoded"}),", you can decode it ",(0,s.jsx)(n.a,{href:"https://www.urldecoder.org/",children:"using an online calculator"}),"."]}),(0,s.jsx)(n.pre,{"data-language":"json","data-theme":"default",children:(0,s.jsxs)(n.code,{"data-language":"json","data-theme":"default",children:[(0,s.jsx)(n.span,{className:"line",children:(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"{"})}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:'"chainId"'}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-constant)"},children:"31337"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:'"address"'}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b"'}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:","})]}),"\n",(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"  "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:'"filters"'}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-punctuation)"},children:":"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" []"})]}),"\n",(0,s.jsx)(n.span,{className:"line",children:(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:"}"})})]})}),(0,s.jsxs)(n.p,{children:["Meaning that the query is for all events in the ",(0,s.jsx)(n.code,{children:"World"})," at address ",(0,s.jsx)(n.code,{children:"0x8d8b6b8414e1e3dcfd4168561b9be6bd3bf6ec4b"}),", on the chain with chain ID ",(0,s.jsx)(n.code,{children:"31337"}),"."]})]}),"\n",(0,s.jsx)(n.h3,{id:"clearing-the-information",children:"Clearing the information"}),"\n",(0,s.jsxs)(n.p,{children:["If you restart the blockchain, you need to clear all the information stored by the indexer otherwise you'll have an inconsistent state.\nThe events are all in the ",(0,s.jsx)(n.code,{children:"mud"})," schema:"]}),"\n",(0,s.jsx)(n.pre,{"data-language":"sql","data-theme":"default",hasCopyCode:!0,children:(0,s.jsx)(n.code,{"data-language":"sql","data-theme":"default",children:(0,s.jsxs)(n.span,{className:"line",children:[(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"DROP"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-keyword)"},children:"SCHEMA"}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" "}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-token-string-expression)"},children:'"mud"'}),(0,s.jsx)(n.span,{style:{color:"var(--shiki-color-text)"},children:" CASCADE;"})]})})})]})}n.default=(0,r.j)(l)},24737:function(e){e.exports={collapsed:"CollapseCode_collapsed__D1CXB",expanded:"CollapseCode_expanded__x1xKU"}}},function(e){e.O(0,[3720,2888,179],function(){return e(e.s=96612)}),_N_E=e.O()}]);