> ## Documentation Index
> Fetch the complete documentation index at: https://docs.forterulesengine.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ExampleERC721

> v0.9.2

[Git Source](https://github.com/Forte-Service-Company-Ltd/forte-rules-engine/blob/496f4da7e579393952d95fe7846fe767b31632a4/src/example/ExampleERC721.sol)

**Inherits:**
ERC721, ReentrancyGuard, ERC721Burnable, [RulesEngineClientERC721](/reference/client/RulesEngineClientERC721.sol/abstract.RulesEngineClientERC721), Ownable

**Author:**
@mpetersoCode55, @ShaneDuncan602, @TJ-Everett, @VoR0220

This contract demonstrates how to integrate the Rules Engine with an ERC721 token for policy enforcement.

*This contract is an example implementation of an ERC721 token integrated with the Rules Engine. It extends the
OpenZeppelin ERC721 and ERC721Burnable contracts and includes additional functionality for interacting with the
Rules Engine. The contract ensures compliance with policies defined in the Rules Engine for minting, transferring,
and transferring tokens on behalf of others. It also includes a withdrawal function for Ether stored in the contract.*

## State Variables

### baseUri

Base Contract URI

```solidity theme={null}
string public baseUri;
```

### counter

```solidity theme={null}
uint256 public counter;
```

## Functions

### constructor

Constructor for the Example ERC721 token.

*Initializes the token with a name and symbol.*

```solidity theme={null}
constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) Ownable(msg.sender);
```

**Parameters**

| Name      | Type     | Description              |
| --------- | -------- | ------------------------ |
| `_name`   | `string` | The name of the token.   |
| `_symbol` | `string` | The symbol of the token. |

### setCallingContractAdmin

Override the default setCallingContractAdmin and add onlyOwner modifier to prevent unauthorized access

```solidity theme={null}
function setCallingContractAdmin(address callingContractAdmin) public override onlyOwner;
```

### setRulesEngineAddress

Override the default setRulesEngineAddress and add onlyOwner modifier to prevent unauthorized access

```solidity theme={null}
function setRulesEngineAddress(address rulesEngine) public override onlyOwner;
```

### safeMint

Mints a new token to the specified address.

*The token ID is incremented by 1 from the previous minted token. This function is payable to allow child
contracts to override it with a priced mint function.*

```solidity theme={null}
function safeMint(address to) public payable virtual onlyOwner checksPoliciesERC721SafeMintAfter(to);
```

**Parameters**

| Name | Type      | Description                   |
| ---- | --------- | ----------------------------- |
| `to` | `address` | The address of the recipient. |

### safeTransferFrom

Safely transfers a token from one address to another.

*This function overrides the [ERC721-safeTransferFrom](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.3.0/contracts/token/ERC721/IERC721.sol#L55) function and interacts with the Rules Engine to ensure
compliance with transfer policies. It includes additional checks for policy compliance.*

```solidity theme={null}
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
    public
    override
    checksPoliciesERC721SafeTransferFromBefore(from, to, tokenId, data);
```

**Parameters**

| Name      | Type      | Description                                        |
| --------- | --------- | -------------------------------------------------- |
| `from`    | `address` | The address of the current token owner.            |
| `to`      | `address` | The address of the recipient.                      |
| `tokenId` | `uint256` | The ID of the token to transfer.                   |
| `data`    | `bytes`   | Additional data to pass to the recipient contract. |

### transferFrom

Transfers a token from one address to another.

*This function overrides the [ERC721-transferFrom](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.3.0/contracts/token/ERC721/IERC721.sol#L91) function and interacts with the Rules Engine to ensure
compliance with transfer policies. It includes additional checks for policy compliance.*

```solidity theme={null}
function transferFrom(address from, address to, uint256 tokenId)
    public
    override
    checksPoliciesERC721TransferFromBefore(from, to, tokenId);
```

**Parameters**

| Name      | Type      | Description                             |
| --------- | --------- | --------------------------------------- |
| `from`    | `address` | The address of the current token owner. |
| `to`      | `address` | The address of the recipient.           |
| `tokenId` | `uint256` | The ID of the token to transfer.        |

### supportsInterface

*Returns true if this contract implements the interface defined by
`interfaceId`. See the corresponding
[https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified\[EIP](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified\[EIP) section]
to learn more about how these ids are created.
This function call must use less than 30 000 gas.*

```solidity theme={null}
function supportsInterface(bytes4 interfaceId) public view override(ERC721) returns (bool);
```

### withdraw

Withdraws Ether stored in the contract.

*This function allows only the owner to withdraw Ether. The function is payable to allow flexibility in child contracts.*

```solidity theme={null}
function withdraw() public payable virtual onlyOwner;
```
