Utilities

getSchema

The SDK uses Zod schemas in order to verify inputs for createNewInstance, according to their target Solidity types. The getSchema function is exported as a utility function, to get the Zod schema for a corresponding Solidity type.

import { getSchema } from "@hatsprotocol/modules-sdk";

const schema = getSchema(solidityType);

Arguments:

solidityType: string

solidityType - The name of the Solidity type, e.g. "uint256".

Response:

ZodType

The Zod schema for the provided type.

verify

Verify a value according to its target Solidity type.

import { verify } from "@hatsprotocol/modules-sdk";

const isValid = verify(val, type);

Arguments:

(val: unknown, type: string)
  • val - The value to verify.

  • type - The target Solidity type for the provided value.

Response:

boolean

true if the provided value is compatible with the Solidity type, false otherwise.

solidityToTypescriptType

Utility function that maps between a Solidity type to its compatible Typescript type.

import { solidityToTypescriptType } from "@hatsprotocol/modules-sdk";

const tsType = solidityToTypescriptType(solidityType);

Arguments:

solidityType: string

solidityType - The name of the Solidity type, e.g. "uint256".

Response:

"number"    | 
"bigint"    |
"string"    |
"boolean"   |
"number[]"  | 
"bigint[]"  | 
"string[]"  | 
"boolean[]" | 
"unknown"

The name of the Typescript type which is compatible to the provided Solidity one.

checkAndEncodeArgs

Check and encode the immutable and mutable arguments for module creation.

This is a utility function for interacting with the HatsModuleFactory directly, rather than using the createNewInstance function from the SDK. This may be useful in cases where the module creation is proxied by another contract and expects similar input parameters as the createHatsModule function from the factory.

import { checkAndEncodeArgs } from "@hatsprotocol/modules-sdk";

const { encodedImmutableArgs, encodedMutableArgs } = checkAndEncodeArgs({
   module,
   immutableArgs,
   mutableArgs,
});

Arguments:

{
  module: Module;
  immutableArgs: unknown[];
  mutableArgs: unknown[];
}

module - The module object of the module that will be created.

immutableArgs - The module's immutable arguments.

mutableArgs - The modules's mutable arguments.

Response:

{
  encodedImmutableArgs: "" | `0x${string}`;
  encodedMutableArgs: "" | `0x${string}`;
}

The encoded immutable and mutable arguments, as expected by the createHatsModule function from the factory.

checkImmutableArgs

Check the immutable arguments for module creation.

Checks that the provided immutable arguments are valid according to the module's schema from the registry. If not, the function will throw a detailed error.

import { checkImmutableArgs } from "@hatsprotocol/modules-sdk";

checkImmutableArgs({ module, immutableArgs });

Arguments:

{
  module: Module;
  immutableArgs: unknown[];
}

module - The module object of the module that will be created.

immutableArgs - The module's immutable arguments.

checkMutableArgs

Check the mutable arguments for module creation.

Checks that the provided mutable arguments are valid according to the module's schema from the registry. If not, the function will throw a detailed error.

import { checkMutableArgs } from "@hatsprotocol/modules-sdk";

checkMutableArgs({ module, mutableArgs });

Arguments:

{
  module: Module;
  mutableArgs: unknown[];
}

module - The module object of the module that will be created.

mutableArgs - The module's mutable arguments.

getNewInstancesFromReceipt

Get the addresses of newly created module instance/s, using the creation transaction receipt.

import { getNewInstancesFromReceipt } from "@hatsprotocol/modules-sdk";

const instances = getNewInstancesFromReceipt(receipt);

Arguments:

receipt: TransactionReceipt

receipt - The transaction receipt as a TransactionReceipt Viem object.

Response:

`0x${string}`[]

An array of the newly created instances/s.

Last updated