Squid for the Reef Chain Sqwid marketplace.
This project has been created with the Reef EVM event processor template.
-
Create a
.env
file with the contents of.env.sample
. -
Start Docker and run the following commands:
# 1. Install dependencies
npm install
# 2. Compile typescript files
make build
# 3. Start target Postgres database and detach
# DB will be available at localhost:23799/evm_events
make up
# 4. Start the processor
make process
# 5. In a separate terminal, start graphql server
# GraphQL API will be available at http://localhost:4350/graphql
make serve
# 6. Stop and destroy target Postgres database
make down
Delete migration files from db/migrations
directory and define the schema of the target database via schema.graphql
file, replacing the sample definition.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql
dialect is available here.
Mapping developers use TypeORM EntityManager
to interact with target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql
. This is done by running the following command:
make codegen
It is necessary to import the respective ABI definition to decode EVM logs.
Delete all the contents in src/abi
and insert the JSON ABI definition of the contract to index.
To generate a type-safe facade class to decode EVM logs execute the following command:
npx squid-evm-typegen src/abi src/abi/{YOUR_CONTRACT_NAME}.json
And replace the following code in generated the generated abi.support.ts
file:
let result = await this._chain.client.call('eth_call', [
{ to: this.address, data },
'0x' + this.blockHeight.toString(16)
])
by
let result = await this._chain.client.call('evm_call', [
{to: this.address, data, from: undefined, storageLimit: 0}
])
Squid tools assume a certain project layout.
- All compiled js files must reside in
lib
and all TypeScript sources insrc
. The layout oflib
must reflectsrc
. - All TypeORM classes must be exported by
src/model/index.ts
(lib/model
module). - Database schema must be defined in
schema.graphql
. - Database migrations must reside in
db/migrations
and must be plain js files. sqd(1)
andsquid-*(1)
executables consult.env
file for a number of environment variables.
It is possible to extend squid-graphql-server(1)
with custom
type-graphql resolvers and to add request validation.
More details will be added later.
- To deploy a Squid execute
sqd deploy -m <path_to_manifest_file>
.