Schemas Config & schemagen
Tool
The schemagen
CLI tool generates libraries for Schemas. It makes it much less error-prone than using the Schemas low-level API, and comes with typed Move APIs when setting and retrieving records.
Using schemagen
with the Obelisk framework
If you are using the Obelisk framework and have a obelisk.config.ts
file in your project, you can edit your Schemas config directly in this file!
A Schemas config should be named obelisk.config.ts
, and placed at the root of your project.
This is the minimal config:
import { ObeliskConfig } from "@0xobelisk/common";
export const obeliskConfig = {
name: "example", // name of the Move project
description: "example desc", // description of the Move project
schemas: {}, // an empty config with no schemas,
} as ObeliskConfig;
Generating the schemas
To generate the schemas, run pnpm obelisk schemagen ./obelisk.config.ts
in the same folder as the config file.
Schema Type
Requires developer-defined entity_key. Obelisk will provide some common methods for generating keys.
Currently, the schema supports five types, and will be added later according to the demand.
schema with a single column
The following three approaches work in the same way
export const obeliskConfig = {
name: "example",
description: "example desc",
schemas: {
single_column1: {
valueType: "vector<u8>"
},
single_column2: "vector<u8>",
single_column3: {
valueType: {
name: "vector<u8>"
}
}
},
} as ObeliskConfig;
schema with a multi column
export const obeliskConfig = {
name: "example",
description: "example desc",
schemas: {
multi_column: {
valueType: {
name: "vector<u8>",
age: "u8",
sex: "bool"
}
}
},
} as ObeliskConfig;
schema with a single value
export const obeliskConfig = {
name: "example",
description: "example desc",
schemas: {
single_value: {
valueType: "u64",
defaultValue: 10
}
}
} as ObeliskConfig;
schema with a single struct
export const obeliskConfig = {
name: "example",
description: "example desc",
schemas: {
single_struct: {
valueType: {
admin: "address",
fee: "u64",
},
defaultValue: {
admin: "0x1",
fee: "100",
}
}
}
} as ObeliskConfig;
ephemeral schema
export const obeliskConfig = {
name: "example",
description: "example desc",
schemas: {
ephemeral_schema: {
ephemeral: true,
valueType: {
result: "u8",
},
}
}
} as ObeliskConfig;