# NFI

The NFI (Non-Fungible Intelligence) pallet allows for enabling NFI compatibility on new or existing collections. Once enabled, when an NFI-compatible NFT/SFT is minted, our trusted relayer will automatically generate the NFI data, storing the resulting NFIData on-chain.

Note: There may be an additional charge for NFTs minted with NFI enabled. See the [**MintFee**](#mint-fee) section below. 0.5% of the mint fee is sent to the Vortex for redistribution to network participants.

***

## Pallet Calls

***

#### Enable NFI

{% hint style="info" %}
***Currently disabled on TRN mainnet.***
{% endhint %}

> Enables NFI compatibility on a collection. Caller must be the collection owner
>
> **Namespace:**
>
> ```
> api.tx.nfi.enableNfi
> ```
>
> **Type:**
>
> ```typescript
> function enableNfi(
>   collection_id: u32,
>   sub_type: SeedPrimitivesNfiNFISubType
> )
> ```

#### Manual Data Request

> Users can manually request NFI data if it does not already exist on a token. This can be used to manually request data for pre-existing tokens in a collection that has had NFI enabled Caller must be either the token owner or the collection owner Note. the mint fee will need to be paid for any manual request
>
> **Namespace:**
>
> ```
> api.tx.nfi.manualDataRequest
> ```
>
> **Type:**
>
> ```typescript
> function manualDataRequest(
>   token_id: (u32,u32),
>   sub_type: SeedPrimitivesNfiNFISubType
> )
> ```

#### Submit NFI Data

> Submit NFI data to the chain. Caller must be the registered relayer. NFI must be enabled for the collection
>
> **Namespace:**
>
> ```
> api.tx.nfi.submitNfiData
> ```
>
> **Type:**
>
> ```typescript
> function submitNfiData(
>   token_id: (u32,u32),
>   data_item: SeedPrimitivesNfiNFIDataType
> )
> ```

#### Set Fee Details (Sudo Only)

> Set the NFI mint fee which is paid per token by the minter. Setting fee\_details to None removes the mint fee
>
> **Namespace:**
>
> ```
> api.tx.nfi.setFeeDetails
> ```
>
> **Type:**
>
> ```typescript
> function setFeeDetails(
>   sub_type: SeedPrimitivesNfiNFISubType,
>   fee_details: Option<SeedPrimitivesNfiFeeDetails>
> )
> ```

#### Set Relayer (Sudo Only)

> Set the relayer address. This address is able to submit the NFI data back to the chain. Caller must be sudo
>
> **Namespace:**
>
> ```
> api.tx.nfi.setRelayer
> ```
>
> **Type:**
>
> ```typescript
> function setRelayer(
>   relayer: SeedPrimitivesSignatureAccountId20,
> )
> ```

#### Set Fee To (Sudo Only)

> Set the 'FeeTo' account. Caller must be sudo
>
> **Namespace:**
>
> ```
> api.tx.nfi.setFeeTo
> ```
>
> **Type:**
>
> ```typescript
> function setFeeTo(
>   fee_to: Option<SeedPrimitivesSignatureAccountId20>,
> )
> ```

***

## Pallet Storage

***

#### Relayer

> Stores the permission enabled relayer account
>
> **Namespace:**
>
> ```
> api.query.nfi.relayer
> ```
>
> **Type:**
>
> ```typescript
> function relayer(): Option<SeedPrimitivesSignatureAccountId20>
> ```

#### Mint Fee

> Stores the extra mint fee that is charged for NFI enabled tokens
>
> **Namespace:**
>
> ```
> api.query.nfi.mintFee
> ```
>
> **Type:**
>
> ```typescript
> function mintFee(
>   SeedPrimitivesNfiNFISubType
> ): SeedPrimitivesNfiFeeDetails
> ```

#### NFI Data

> Stores the NFI Data linked to a token
>
> **Namespace:**
>
> ```
> api.query.nfi.nfiData
> ```
>
> **Type:**
>
> ```typescript
> function nfiData(
>   (u32,u32), // token_id
>   SeedPrimitivesNfiNFISubType
> ): SeedPrimitivesNfiDataType
> ```

#### NFI Enabled

> Whether or not NFI is enabled for a collection
>
> **Namespace:**
>
> ```
> api.query.nfi.nfiEnabled
> ```
>
> **Type:**
>
> ```typescript
> function nfiEnabled(
>   u32, // collection_id
>   SeedPrimitivesNfiNFISubType
> ): boolean
> ```

#### Fee To

> The Fee To address that collects network fees
>
> **Namespace:**
>
> ```
> api.query.nfi.feeTo
> ```
>
> **Type:**
>
> ```typescript
> function feeTo(): Option<SeedPrimitivesSignatureAccountId20>
> ```

***

## Pallet Events

***

#### Data Request

> Request for new NFI data creation
>
> **Namespace:**
>
> ```
> api.events.nfi.DataRequest
> ```
>
> **Type:**
>
> ```typescript
> type DataRequest = {
>   sub_type: SeedPrimitivesNfiNFISubType,
>   caller: SeedPrimitivesSignatureAccountId20,
>   collection_id: u32,
>   serial_numbers: Vec<u32>
> }
> ```

#### Data Set

> A new NFI storage item has been set
>
> **Namespace:**
>
> ```
> api.events.nfi.DataSet
> ```
>
> **Type:**
>
> ```typescript
> type DataSet = {
>   sub_type: SeedPrimitivesNfiNFISubType,
>   token_id: (u32,u32),
>   data_item: SeedPrimitivesNfiNFIDataType
> }
> ```

#### Data Removed

> NFI storage has been removed for a token
>
> **Namespace:**
>
> ```
> api.events.nfi.DataRemoved
> ```
>
> **Type:**
>
> ```typescript
> type DataRemoved = {
>   token_id: (u32,u32)
> }
> ```

#### Fee Details Set

> New fee details have been set
>
> **Namespace:**
>
> ```
> api.events.nfi.FeeDetailsSet
> ```
>
> **Type:**
>
> ```typescript
> type FeeDetailsSet = {
>   sub_type: SeedPrimitivesNfiNFISubType,
>   fee_details: SeedPrimitivesNfiFeeDetails
> }
> ```

#### Fee To Set

> The network fee receiver address has been updated
>
> **Namespace:**
>
> ```
> api.events.nfi.FeeToSet
> ```
>
> **Type:**
>
> ```typescript
> type FeeToSet = {
>   account: SeedPrimitivesSignatureAccountId20
> }
> ```

#### Mint Fee Paid

> Additional mint fee has been paid to the receiver address
>
> **Namespace:**
>
> ```
> api.events.nfi.MintFeePaid
> ```
>
> **Type:**
>
> ```typescript
> type MintFeePaid = {
>   sub_type: SeedPrimitivesNfiNFISubType,
>   who: SeedPrimitivesSignatureAccountId20,
>   asset_id: u32,
>   total_fee: u128
> }
> ```

#### NFI Enabled

> NFI compatibility enabled for a collection
>
> **Namespace:**
>
> ```
> api.events.nfi.NfiEnabled
> ```
>
> **Type:**
>
> ```typescript
> type NfiEnabled = {
>   sub_type: SeedPrimitivesNfiNFISubType,
>   collection_id: u32,
> }
> ```

#### Relayer Set

> A new relayer has been set
>
> **Namespace:**
>
> ```
> api.events.nfi.RelayerSet
> ```
>
> **Type:**
>
> ```typescript
> type RelayerSet = {
>   account: SeedPrimitivesSignatureAccountId20
> }
> ```

***

## Pallet Errors

***

#### Invalid Mint Fee

> The mint fee must be a valid integer above 0
>
> **Namespace:**
>
> ```
> api.errors.nfi.InvalidMintFee
> ```

#### Not Enabled

> NFI storage is not enabled for this collection
>
> **Namespace:**
>
> ```
> api.errors.nfi.NotEnabled
> ```

#### Not Relayer

> The caller is not the relayer and does not have permission to perform this action
>
> **Namespace:**
>
> ```
> api.errors.nfi.NotRelayer
> ```

#### Not Collection Owner

> The caller is not the collection owner and does not have permission to perform this action
>
> **Namespace:**
>
> ```
> api.errors.nfi.NotCollectionOwner
> ```

#### Not Token Owner

> The caller is not the token owner and does not have permission to perform this action
>
> **Namespace:**
>
> ```
> api.errors.nfi.NotTokenOwner
> ```

#### No Token

> The token does not exist
>
> **Namespace:**
>
> ```
> api.errors.nfi.NoToken
> ```

***

## Pallet Constants

***

#### Network Fee Percentage

> Percentage of sale price to charge for network fees
>
> **Namespace:**
>
> ```
> api.consts.nfi.NetworkFeePercentage
> ```
>
> **Type:**
>
> ```typescript
> type NetworkFeePercentage = Permill
> ```

#### Max Data Length

> Maximum length of data stored per token
>
> **Namespace:**
>
> ```
> api.consts.nfi.MaxDataLength
> ```
>
> **Type:**
>
> ```typescript
> type MaxDataLength = u32
> ```
