Skip to main content

Permissions

Functionality available for contracts that inherit the Permissions contract.

Allows you to manage the roles and permissions of the smart contract.

Roles include admin, transfer, minter, pauser, lister, asset, unwrap, factory, or any other custom roles you have created.

get

Get a list of wallet addresses that are members of a given role.

const members = await contract.roles.get("{{role_name}}");
Configuration

role

The name of the role.

Must be a string.

const members = await contract.roles.get(
"{{role_name}}",
);

Return Value

An array of strings representing the wallet addresses associated with the given role.

string[];

getAll

Retrieve all of the roles and associated wallets.

const allRoles = await contract.roles.getAll();
Configuration

Return Value

An object containing role names as keys and an array of wallet addresses as the value.

<Record<any, string[]>>

grant

Make a wallet a member of a given role.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration

role

The name of the role to grant.

Must be a string.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);

wallet

The wallet address to assign the role to.

Must be a string.

const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);

revoke

Revoke a given role from a wallet.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration

role

The name of the role to revoke.

Must be a string.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);

wallet

The wallet address to remove the role from.

Must be a string.

const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);

setAll

Overwrite all roles with new members.

Dangerous Operation

This overwrites all members, INCLUDING YOUR OWN WALLET ADDRESS!

This means you can permanently remove yourself as an admin, which is non-reversible.

Please use this method with caution.

const txResult = await contract.roles.setAll({
admin: ["0x12", "0x123"],
minter: ["0x1234"],
});
Configuration

roles

An object containing role names as keys and an array of wallet addresses as the value.

const txResult = await contract.roles.setAll(
{
admin: ["0x12", "0x123"], // Grant these two wallets the admin role
minter: ["0x1234"], // Grant this wallet the minter role
},
);

verify

Check to see if a wallet has a set of roles.

Throws an error if the wallet does not have any of the given roles.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_addres}}",
);
Configuration

roles

An array of roles to check.

Must be an array of strings.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_addres}}",
);

wallet

The wallet address to check.

Must be a string.

const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_addres}}",
);