Interact With Instances

The following functions provide utilities to support the interaction with module instances: checking whether a certain instance was created, reading instance's display parameters (as specified in the 'parameter' property in the Module's object) and calling its write functions.

To get the module's object from an instance address, use this function.

isModuleDeployed

Check if a module is already deployed, using its creation arguments.

const isDeployed = await hatsModulesClient.isModuleDeployed({
    moduleId,
    hatId,
    immutableArgs,
    saltNonce,
});

Arguments:

{
   moduleId: string;
   hatId: bigint;
   immutableArgs: unknown[];
   saltNonce: bigint;
}

Response:

boolean

true if the module was deployed, false otherwise.

getInstanceParameters

Get a module's instance live parameters.

The parameters to fetch are listed in the Module's registry object (in the 'parameters' property), and their purpose is to display relevant information for each module instance.

const module = await hatsModulesClient.getInstanceParameters(instance);

Arguments:

instance: `0x${string}`

instance - Instance's address.

Response:

{
  label: string;
  value: unknown;
  solidityType: string;
  displayType: string;
}[]

An array of objects, each containing a parameter's information:

  • label - The parameter's name/description.

  • value - The parameter's value, as was returned from the instance contract.

  • solidityType - The parameter's Solidity type.

  • displayType- The parameter's display type. Its purpose is for UIs to be able to render an appropriate component for the parameter. For example, rendering a date for timestamps.

callInstanceWriteFunction

Call a module's write function.

The 'customRoles' and 'writeFunctions' properties of a Module's object enable to programmatically get all the write functions of a module, together with any necessary information to call them: expected input arguments and the roles (Hats) that have the permission to call each function.

const res = await hatsModulesClient.callInstanceWriteFunction({
    account,
    moduleId,
    instance,
    func,
    args,
});

Arguments:

{
    account: Account | Address;
    moduleId: string;
    instance: Address;
    func: WriteFunction;
    args: unknown[];
}
  • account - Viem account (Address for JSON-RPC accounts or Account for other types).

  • moduleId - Module's ID (implementation address).

  • instance - Instance's address.

  • func - The function to call, provided as an object of WriteFunction type.

  • args - The input arguments to pass the function.

Response:

{
  status: "success" | "reverted";
  transactionHash: `0x${string}`;
}
  • status - "success" if transaction was successful, "reverted" if transaction reverted.

  • transactionHash - transaction's hash.

Last updated