Skip to main content

Permissions and Roles

Using the Permissions and Roles features on your contract allows you to add a fine-tuned permission control system to control who is allowed to interact with different parts of your contract functionality.

You can add this interface to your contract by implementing all of the functions in the IPermissionsEnumerable interface as shown below:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@thirdweb-dev/contracts/ThirdwebContract.sol";
import "@thirdweb-dev/contracts/feature/interface/IPermissionsEnumerable.sol";

// We add the interface to the contract
contract MyCustomContract is ThirdwebContract, IPermissionsEnumerable {

// Implement the permissions functions below

}

Alternatively, you can use our PermissionsEnumerable implementation of the IPermissionsEnumerable interface to get permissions functionality for your contract out-of-the-box as follows:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@thirdweb-dev/contracts/ThirdwebContract.sol";
import "@thirdweb-dev/contracts/feature/interface/PermissionsEnumerable.sol";

// We add the interface to the contract
contract MyCustomContract is ThirdwebContract, PermissionsEnumerable {

// Now this contract will have permissions out of the box

}

If your contract implements all the functions in this standard, you will get support for the following SDK interface.

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

get

Call this to get a list of addresses that are members of a specific role.

const minterAddresses: string[] = await contract.getRoleMemberList("minter");
View in Javascript SDK Documentation

setAll

Call this to OVERWRITE the list of addresses that are members of specific roles. 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 {@link ContractRoles.grant} and {@link ContractRoles.revoke} respectively instead.

const minterAddresses: string[] = await contract.getRoleMemberList("minter");
await contract.setAll({
minter: []
});
console.log(await contract.getRoleMemberList("minter")); // No matter what members had the role before, the new list will be set to []
View in Javascript SDK Documentation