SoulboundERC721A
The SoulboundERC721A
extension smart contract is meant to be used with ERC721A contracts as its base. It provides the appropriate before transfer
hook for ERC721A, where it checks whether a given transfer is valid to go through or not. This contract uses the Permissions
extension, and creates a role 'TRANSFER_ROLE'. - If address(0)
holds the transfer role, then all transfers go through. - Else, a transfer goes through only if either the sender or recipient holds the transfer role.
Methods
DEFAULT_ADMIN_ROLE
function DEFAULT_ADMIN_ROLE() external view returns (bytes32)
Returns
Name | Type | Description |
---|---|---|
_0 | bytes32 | undefined |
TRANSFER_ROLE
function TRANSFER_ROLE() external view returns (bytes32)
Only transfers to or from TRANSFER_ROLE holders are valid, when transfers are restricted.
Returns
Name | Type | Description |
---|---|---|
_0 | bytes32 | undefined |
getRoleAdmin
function getRoleAdmin(bytes32 role) external view returns (bytes32)
Returns the admin role that controls the specified role.
See {grantRole} and {revokeRole}. To change a role's admin, use {_setRoleAdmin}.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
Returns
Name | Type | Description |
---|---|---|
_0 | bytes32 | undefined |
getRoleMember
function getRoleMember(bytes32 role, uint256 index) external view returns (address member)
Returns the role-member from a list of members for a role, at a given index.
Returns member
who has role
, at index
of role-members list. See struct {RoleMembers}, and mapping {roleMembers}
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
index | uint256 | Index in list of current members for the role. |
Returns
Name | Type | Description |
---|---|---|
member | address | Address of account that has role |
getRoleMemberCount
function getRoleMemberCount(bytes32 role) external view returns (uint256 count)
Returns total number of accounts that have a role.
Returns count
of accounts that have role
. See struct {RoleMembers}, and mapping {roleMembers}
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
Returns
Name | Type | Description |
---|---|---|
count | uint256 | Total number of accounts that have role |
grantRole
function grantRole(bytes32 role, address account) external nonpayable
Grants a role to an account, if not previously granted.
Caller must have admin role for the role
. Emits {RoleGranted Event}.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
account | address | Address of the account to which the role is being granted. |
hasRole
function hasRole(bytes32 role, address account) external view returns (bool)
Checks whether an account has a particular role.
Returns true
if account
has been granted role
.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
account | address | Address of the account for which the role is being checked. |
Returns
Name | Type | Description |
---|---|---|
_0 | bool | undefined |
hasRoleWithSwitch
function hasRoleWithSwitch(bytes32 role, address account) external view returns (bool)
Checks whether an account has a particular role; role restrictions can be switched on and off.
Returns true
if account
has been granted role
. Role restrictions can be switched on and off: - If address(0) has ROLE, then the ROLE restrictions don't apply. - If address(0) does not have ROLE, then the ROLE restrictions will apply.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
account | address | Address of the account for which the role is being checked. |
Returns
Name | Type | Description |
---|---|---|
_0 | bool | undefined |
renounceRole
function renounceRole(bytes32 role, address account) external nonpayable
Revokes role from the account.
Caller must have the role
, with caller being the same as account
. Emits {RoleRevoked Event}.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
account | address | Address of the account from which the role is being revoked. |
restrictTransfers
function restrictTransfers(bool _toRestrict) external nonpayable
Restrict transfers of NFTs.
Restricting transfers means revoking the TRANSFER_ROLE from address(0). Making transfers unrestricted means granting the TRANSFER_ROLE to address(0).
Parameters
Name | Type | Description |
---|---|---|
_toRestrict | bool | Whether to restrict transfers or not. |
revokeRole
function revokeRole(bytes32 role, address account) external nonpayable
Revokes role from an account.
Caller must have admin role for the role
. Emits {RoleRevoked Event}.
Parameters
Name | Type | Description |
---|---|---|
role | bytes32 | keccak256 hash of the role. e.g. keccak256("TRANSFER_ROLE") |
account | address | Address of the account from which the role is being revoked. |
Events
RoleAdminChanged
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole)
Parameters
Name | Type | Description |
---|---|---|
role indexed | bytes32 | undefined |
previousAdminRole indexed | bytes32 | undefined |
newAdminRole indexed | bytes32 | undefined |
RoleGranted
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender)
Parameters
Name | Type | Description |
---|---|---|
role indexed | bytes32 | undefined |
account indexed | address | undefined |
sender indexed | address | undefined |
RoleRevoked
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender)
Parameters
Name | Type | Description |
---|---|---|
role indexed | bytes32 | undefined |
account indexed | address | undefined |
sender indexed | address | undefined |
TransfersRestricted
event TransfersRestricted(bool isRestricted)
Parameters
Name | Type | Description |
---|---|---|
isRestricted | bool | undefined |