Class ContractRoles<TContract, TRole>

Handle contract permissions

Remarks

Configure roles and permissions for a contract, to restrict certain actions.

Example

const contract = await sdk.getContract("{{contract_address}}");
const rolesAndMembers = await contract.roles.getAll();
await contract.roles.grantRole("admin", "0x...");

Type Parameters

  • TContract extends IPermissions

  • TRole extends Role

Hierarchy

  • ContractRoles

Implements

  • DetectableFeature

Constructors

  • Type Parameters

    • TContract extends IPermissions

    • TRole extends "metadata" | "transfer" | "signer" | "minter" | "revoke" | "admin" | "pauser" | "lister" | "asset" | "unwrap" | "factory"

    Parameters

    • contractWrapper: ContractWrapper<IPermissions>
    • roles: readonly TRole[]

    Returns ContractRoles<TContract, TRole>

Properties

contractWrapper: ContractWrapper<IPermissions>
featureName: "Permissions" = FEATURE_PERMISSIONS.name
grant: {
    prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>);
    (...args): Promise<TResult>;
} = ...

Type declaration

    • (...args): Promise<TResult>
    • Grant a role to a specific address

      Parameters

      • Rest ...args: [role: TRole, address: string]

      Returns Promise<TResult>

      The transaction receipt

      Remarks

      Make sure you are sure you want to grant the role to the address.

      Example

      await contract.roles.grant("minter", "{{wallet_address}}");
      

      Throws

      If you are trying to grant does not exist on the contract this will throw an error.

      Twfeature

      Permissions

  • prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>)
      • (...args): Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>
      • Parameters

        • Rest ...args: [role: TRole, address: string]

        Returns Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>

revoke: {
    prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>);
    (...args): Promise<TResult>;
} = ...

Type declaration

    • (...args): Promise<TResult>
    • Revoke a role from a specific address

      Parameters

      • Rest ...args: [role: TRole, address: string]

      Returns Promise<TResult>

      The transaction receipt

      Remarks

      -- Caution --

      This will let you remove yourself from the role, too. If you remove yourself from the admin role, you will no longer be able to administer the contract. There is no way to recover from this.

      Example

      await contract.roles.revoke("minter", "{{wallet_address}}");
      

      Throws

      If you are trying to revoke does not exist on the module this will throw an error.

      Twfeature

      Permissions

  • prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>)
      • (...args): Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>
      • Parameters

        • Rest ...args: [role: TRole, address: string]

        Returns Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>

setAll: {
    prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>);
    (...args): Promise<TResult>;
} = ...

Type declaration

    • (...args): Promise<TResult>
    • Overwrite the list of members for specific roles

      Parameters

      • Rest ...args: [rolesWithAddresses: {
            [key in "metadata" | "transfer" | "signer" | "minter" | "revoke" | "admin" | "pauser" | "lister" | "asset" | "unwrap" | "factory"]?: string[]
        }]

      Returns Promise<TResult>

      Remarks

      Every role in the list will be overwritten with the new list of addresses provided with them. If you want to add or remove addresses for a single address use ContractRoles.grant and ContractRoles.revoke respectively instead.

      Throws

      If you are requesting a role that does not exist on the contract this will throw an error.

      Example

      Say you want to overwrite the list of addresses that are members of the minter role.

      const minterAddresses = await contract.roles.get("minter");
      await contract.roles.setAll({
      minter: []
      });
      console.log(await contract.roles.get("minter")); // No matter what members had the role before, the new list will be set to []

      Twfeature

      Permissions

  • prepare: ((...args) => Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>)
      • (...args): Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>
      • Parameters

        • Rest ...args: [rolesWithAddresses: {
              [key in "metadata" | "transfer" | "signer" | "minter" | "revoke" | "admin" | "pauser" | "lister" | "asset" | "unwrap" | "factory"]?: string[]
          }]

        Returns Promise<Transaction<Omit<TransactionResultWithMetadata<unknown>, "data">>>

Methods

  • Get all members of a specific role

    Parameters

    • role: TRole

      The Role to to get a memberlist for.

    Returns Promise<string[]>

    The list of addresses that are members of the specific role.

    Remarks

    See ContractRoles.getAll to get get a list of addresses for all supported roles on the contract.

    Throws

    If you are requesting a role that does not exist on the contract this will throw an error.

    Example

    Say you want to get the list of addresses that are members of the minter role.

    const minterAddresses = await contract.roles.get("minter");
    

    Twfeature

    Permissions

  • Get all members of all roles

    Returns Promise<Record<TRole, string[]>>

    A record of Roles to lists of addresses that are members of the given role.

    Remarks

    See ContractRoles.get to get a list of addresses that are members of a specific role.

    Example

    const rolesAndMembers = await contract.roles.getAll();
    

    Throws

    If the contract does not support roles this will throw an error.

    Twfeature

    PermissionsEnumerable

Generated using TypeDoc