# Schemas

## Types

### Schema (Onchain)

| Name          | Type                       | Description                                                                                                                                                              |
| ------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| name          | `string`                   | Schema name.                                                                                                                                                             |
| description?  | `string`                   | Schema description.                                                                                                                                                      |
| revocable?    | `boolean`                  | Whether Attestations that adopt this Schema can be revoked.                                                                                                              |
| maxValidFor?  | `number`                   | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`.        |
| hook?         | `address`                  | The contract address of the hook for this schema.                                                                                                                        |
| registrant    | `address`                  | The wallet address of the user that registered this schema.                                                                                                              |
| dataLocation? | `DataLocationOnChain`      | Where `Schema.data` is stored. See `DataLocation.DataLocation`.                                                                                                          |
| data          | `SchemaItem[]` or `string` | The data format defining this schema's data structure. When `dataLocation=ONCHAIN`, data is `SchemaItem[]`, when `dataLocation=ARWEAVE or IPFS`, data is id of the data. |

### Schema (Offchain)

| Name          | Type                   | Description                                                                                                                                                       |
| ------------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name          | `string`               | Schema name.                                                                                                                                                      |
| description?  | `string`               | Schema description.                                                                                                                                               |
| revocable?    | `boolean`              | Whether Attestations that adopt this Schema can be revoked.                                                                                                       |
| maxValidFor?  | `number`               | The maximum number of seconds that an Attestation can remain valid. 0 means Attestations can be valid forever. This is enforced through `Attestation.validUntil`. |
| dataLocation? | `DataLocationOffChain` | Where `Schema.data` is stored. See `DataLocation.DataLocation`.                                                                                                   |
| data          | `SchemaItem[]`         | The data format defining this schema's data structure.                                                                                                            |

## Usage

### Registering a Schema

```ts
async function createSchema(
  schema: Schema,
  options?: { getTxHash?: (txHash: `0x${string}`) => void }
): Promise<SchemaResult>;
```

#### Parameters

| Name     | Type                  | Description                    |
| -------- | --------------------- | ------------------------------ |
| schema   | `Schema`              | The schema being registered.   |
| options? | `CreateSchemaOptions` | Options for creating a schema. |

#### CreateSchemaOptions

| Name                 | Type                                | Description                                                                                                           |
| -------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| delegationSignature? | string                              | The user's delegate signature for creating a schema on their behalf. Call `delegateSignSchema` to get this signature. |
| getTxHash?           | ``(txHash: `0x${string}`) => void`` | An optional callback that immediately returns the transaction hash.                                                   |

#### Example

```typescript
const res = await client.createSchema({
  name: "Example",
  data: [{ name: "name", type: "string" }],
});
```

### Retrieving a Schema

```ts
async function getSchema(schemaId: string): Promise<Schema>;
```

#### Parameters

| Name     | Type     | Description                                     |
| -------- | -------- | ----------------------------------------------- |
| schemaId | `string` | The ID of the schema we are trying to retrieve. |

#### Example

```typescript
const res = await client.getSchema("0x3e");
```

### Delegating On-chain Schema Registration via ECDSA

```ts
async function delegateSignSchema(
  schema: OnChainSchema,
  options: DelegateSignSchemaOptions
): Promise<SchemaDelegationSignature>;
```

#### Parameters

| Name    | Type                        | Description                              |
| ------- | --------------------------- | ---------------------------------------- |
| schema  | `OnChainSchema`             | An on-chain schema.                      |
| options | `DelegateSignSchemaOptions` | Options for delegate signing the schema. |

#### DelegateSignSchemaOptions

| Name               | Type                |                                                                                                                                |
| ------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| chain              | `EvmChains`         | The EVM chain you are targetting.                                                                                              |
| delegationAccount? | `PrivateKeyAccount` | The signer account that signs the message. See `viem/accounts`. If this is null, a signer from `window.ethereum` will be used. |
| rpcUrl?            | `string`            | Optional RPC URL.                                                                                                              |
| walletClient?      | `WalletClient`      | Optional `WalletClient` from viem to use for transactions.                                                                     |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sign.global/for-builders/index-1/npm-sdk/usage/schemas.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
