> For the complete documentation index, see [llms.txt](https://docs.legitimate.tech/technical-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.legitimate.tech/technical-docs/protocol/smart-contracts/locked721.md).

# Locked721

## Locked721Base

{% hint style="info" %}
Legitimate maps each unique digital ID to a token on a decentralized blockchain network. For simplicity and consistency, our documentation will refer to each digital ID as a token.
{% endhint %}

At the core of Legitimate's token smart contracts is the `Locked721Base` smart contract.

The `Locked721Base` smart contract is an implementation of [ERC-5192](https://eips.ethereum.org/EIPS/eip-5192).

However, the `Locked721Base` contract adds additional functionality that makes the tokens locked state mutable.

Each token can be locked or unlocked individually, providing granular control over the locked state.

[`ILocked721Base`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/ILocked721Base.sol) provides the high level interface for setting and getting the locked state of each token. Furthermore, ILocked721Base defines [`claim`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/ILocked721Base.sol#L35), which is a function designed for `API_DELEGATE` users to transfer locked tokens without modifying their locked state.

[`Locked721Base`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/Locked721Base.sol) is the implementation of the interface. This adds additional functions that allow third-party contracts and users with the role of [`API_DELEGATE`](/technical-docs/protocol/smart-contracts/access-control-roles.md#api_delegate_role) to modify the locked state of each token.

### Helper Functions

`Locked721Base` itself does not implement `IERC721`. This is intentional in design. `Locked721Base` is an abstract class that allows developers to chose their own `ERC721` implementation. However, `Locked721Base` provides two helper methods designed to be called within the hooks an `ERC721` implementation

#### [`_shouldPreventTokenTransfer`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/Locked721Base.sol#L77)

This helper function will return true if a token is locked and the option `shouldPreventTransferWhenLocked` is `true`

#### [`_lockTokensAfterTransfer`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/Locked721Base.sol#L95)

This helper function will iterate through a set of `tokenIds` and set the locked state to `true.`

If the calling method is a `mint` call (the `from` address is `0x0`) and `shouldLockTokensAfterMint` is set to false, then this function will not set the locked state to `true`.

### Options

[**`shouldLockTokensAfterMint`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/Locked721Base.sol#L12)

This is a configurable option in the contract that defines whether or not tokens should be auto-locked after mint. By default, this is set to true.

[**`shouldPreventTransferWhenLocked`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/base/Locked721Base.sol#L19)

This is a configurable option that determines whether any token in a locked state can be transfered successfully. If this flag is set to true, any transaction that attempts to transfer a locked token will revert. By default, this is set to true.

## Locked721 and Locked721Psi

Legitimate provides two default implementations of `Locked721Base`: [`Locked721`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721.sol) (an implementation of [OpenZeppelin's ERC721 contract](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC721/ERC721.sol)) and [`Locked721Psi`](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721Psi.sol) (an implementation of [ERC721Psi](https://github.com/estarriolvetch/ERC721Psi)).

Each of these are representative of their own ERC721 implementation. We won't get into too much detail about each of the underlying ERC721 implementations, but we will cover how both of these contracts implement `Locked721Base`.

[**`_beforeTokenTransfer`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721.sol#L21) **and** [**`_beforeTokenTransfers`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721Psi.sol#L21)

These hooks call [`_shouldPreventTokenTransfer`](#_shouldpreventtokentransfer) to determine whether or not locked tokens can be transferred by their owners.

[**`_afterTokenTransfers`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721.sol#L35) **and** [**`_afterTokenTransfers`**](https://github.com/LegitimateTech/lgt-phygital-nft-v3/blob/main/contracts/LockedNFT/Locked721Psi.sol#L35)

These hooks call [`_lockTokensAfterTransfer`](#_locktokensaftertransfer) to set the locked state of the transferred tokens after a transfer.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.legitimate.tech/technical-docs/protocol/smart-contracts/locked721.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
