Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TokenTransferable

Git Source

Inherits: ContextUpgradeable

Author: EVMAuth

Manages token transferability settings for soulbound functionality.

Abstract contract enabling tokens to be marked as non-transferable (i.e. "soulbound"). Uses EIP-7201 storage pattern for upgrade safety.

State Variables

TokenTransferableStorageLocation

EIP-7201 storage slot for TokenTransferable state.

Computed as: keccak256(abi.encode(uint256(keccak256("tokentransferable.storage.TokenTransferable")) - 1)) & ~bytes32(uint256(0xff)). Prevents storage collisions in upgradeable contracts.

bytes32 private constant TokenTransferableStorageLocation =
    0xdaa3d1cf82c71b982a9e24ff7dadd71a10e8c3e82a219c0e60ca5c6b8e617700;

Functions

_getTokenTransferableStorage

Retrieves the storage struct for TokenTransferable.

Internal function using inline assembly for direct storage access.

function _getTokenTransferableStorage() private pure returns (TokenTransferableStorage storage $);

Returns

NameTypeDescription
$TokenTransferableStorageStorage pointer to TokenTransferableStorage struct

tokenTransferable

Validates single token transferability.

Modifier allowing mints/burns but blocking transfers of soulbound tokens. Apply to single-token transfer functions like ERC6909's _update

Note: throws: TokenIsNonTransferable When attempting to transfer soulbound token

modifier tokenTransferable(address from, address to, uint256 id);

Parameters

NameTypeDescription
fromaddressSource address (zero for mints)
toaddressDestination address (zero for burns)
iduint256Token type identifier to check

allTokensTransferable

Validates batch token transferability.

Modifier allowing mints/burns but blocking transfers of soulbound tokens. Apply to batch transfer functions like ERC1155's _update.

Note: throws: TokenIsNonTransferable When any token in batch is soulbound

modifier allTokensTransferable(address from, address to, uint256[] memory ids);

Parameters

NameTypeDescription
fromaddressSource address (zero for mints)
toaddressDestination address (zero for burns)
idsuint256[]Array of token type identifiers to check

__TokenTransferable_init

Internal initializer for TokenTransferable setup.

Currently empty as no initialization needed.

function __TokenTransferable_init() internal onlyInitializing;

__TokenTransferable_init_unchained

Unchained initializer for contract-specific storage.

Currently empty but reserved for future initialization.

function __TokenTransferable_init_unchained() internal onlyInitializing;

isTransferable

Checks if token type allows transfers.

Returns transferability status.

function isTransferable(uint256 id) public view virtual returns (bool);

Parameters

NameTypeDescription
iduint256Token type identifier

Returns

NameTypeDescription
<none>boolTrue if transferable, false if soulbound

_setTransferable

Internal function to configure token transferability.

Sets whether token type is transferable or soulbound.

function _setTransferable(uint256 id, bool transferable) internal virtual;

Parameters

NameTypeDescription
iduint256Token type identifier
transferableboolTrue for transferable, false for soulbound

Errors

TokenIsNonTransferable

Error for transfer attempts on soulbound tokens.

error TokenIsNonTransferable(uint256 id);

Parameters

NameTypeDescription
iduint256Token type identifier that is non-transferable

Structs

TokenTransferableStorage

Note: storage-location: erc7201:tokentransferable.storage.TokenTransferable

struct TokenTransferableStorage {
    mapping(uint256 => bool) transferable;
}