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

# E721Farm

[Git Source](https://github.com/Sperax/Demeter-Protocol/blob/cc93b9106874316d6dd016cdace652e2ca4ef8e1/contracts/e721-farms/E721Farm.sol)

**Inherits:** Farm, IERC721Receiver

**Author:** Sperax Foundation.

This contract contains the core logic for E721 farms.

## State Variables

### nftContract

```solidity
address public nftContract;
```

### depositToTokenId

```solidity
mapping(uint256 => uint256) public depositToTokenId;
```

## Functions

### onERC721Received

Function is called when user transfers the NFT to this farm.

```solidity
function onERC721Received(address, address _from, uint256 _tokenId, bytes calldata _data)
    external
    override
    returns (bytes4);
```

**Parameters**

| Name       | Type      | Description                                                   |
| ---------- | --------- | ------------------------------------------------------------- |
| `<none>`   | `address` |                                                               |
| `_from`    | `address` | The address of the owner.                                     |
| `_tokenId` | `uint256` | NFT Id generated by other protocol (e.g. Camelot or Uniswap). |
| `_data`    | `bytes`   | The data should be the lockup flag (bool).                    |

**Returns**

| Name     | Type     | Description                           |
| -------- | -------- | ------------------------------------- |
| `<none>` | `bytes4` | bytes4 The onERC721Received selector. |

### withdraw

Function to withdraw a deposit from the farm.

```solidity
function withdraw(uint256 _depositId) external override nonReentrant;
```

**Parameters**

| Name         | Type      | Description                            |
| ------------ | --------- | -------------------------------------- |
| `_depositId` | `uint256` | The id of the deposit to be withdrawn. |

### \_getLiquidity

Function to get the liquidity. Must be defined by the farm.

*This function should be overridden to add the respective logic.*

```solidity
function _getLiquidity(uint256 _tokenId) internal view virtual returns (uint256);
```

**Parameters**

| Name       | Type      | Description      |
| ---------- | --------- | ---------------- |
| `_tokenId` | `uint256` | The nft tokenId. |

**Returns**

| Name     | Type      | Description                        |
| -------- | --------- | ---------------------------------- |
| `<none>` | `uint256` | The liquidity of the nft position. |

## Errors

### UnauthorisedNFTContract

```solidity
error UnauthorisedNFTContract();
```

### NoData

```solidity
error NoData();
```
