A state-based indexer and API builder for the Cosmos SDK built by and for DAO DAO.
-
Create
config.json
from exampleconfig.json.example
. -
Install dependencies.
npm install
-
Build the indexer.
npm run build
-
Setup the database.
# try migrating to generate the migrations table # this should FAIL, but that is ok npm run db:migrate:data npm run db:setup
-
Run the exporter or server.
npm run export:prod # OR npm run serve:prod
-
Tell pm2 to run on startup.
pm2 startup
Test the indexer:
npm run test
Build the indexer:
npm run build
Run the exporter:
npm run export
Run the API server:
npm run serve
Spawn a console to interact with the various database models and API formulas:
npm run console
To understand how this indexer works and why it exists, read through the documentation.
REVOKE ALL ON DATABASE db FROM readonly_user;
-- revoke access from all databases
SELECT format('REVOKE ALL ON DATABASE %I FROM readonly_user;', datname) FROM pg_database \gexec
-- grant connection access to all databases
SELECT format('GRANT CONNECT, SELECT ON DATABASE %I TO readonly_user;', datname) FROM pg_database WHERE datname = 'accounts' OR datname LIKE '%_%net' \gexec
-- grant access to use SELECT on all tables
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_user;
-- grant access to list tables
GRANT USAGE ON SCHEMA public TO readonly_user;
-- grant read access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly_user;
SELECT DISTINCT ON("codeId") "codeId", "value" FROM "WasmStateEvents" INNER JOIN "Contracts" ON "Contracts"."address" = "WasmStateEvents"."contractAddress" WHERE "key" = '' ORDER BY "codeId" ASC;
Find by contract name (key is contract_info
)
SELECT DISTINCT ON("codeId") "codeId", "value" FROM "WasmStateEvents" INNER JOIN "Contracts" ON "Contracts"."address" = "WasmStateEvents"."contractAddress" WHERE "key" = '99,111,110,116,114,97,99,116,95,105,110,102,111' AND value LIKE '%CONTRACT_NAME%' ORDER BY "codeId" ASC;
Credit to ekez for the initial idea and design of the state-based x/wasm indexer, and noah for the subsequent architecting, implementation, and optimization. Built for DAO DAO and the CosmWasm ecosystem as a whole.