# Fee Controller

### Functions

<details>

<summary>Create an instance</summary>

```typescript
const fee = new FeeController({
    baseUrl: 'http://localhost:8000',
    walletType: {
        embedded: true, // for external wallet it should be false
        supportAa: boolean
    },
    selectedChainName,
    environment = "mainnet",
    aa,
    selectedWallet,
} as TriaArgs);
```

</details>

<details>

<summary>Get Send Fee</summary>

```typescript
getSendFee({
    chain,
    payload,
  }: {
    chain: ChainData;
    payload: Send;
  }): Promise<FeeResponse>
```

</details>

<details>

<summary>Check Token Allowance</summary>

```typescript
checkTokenAllowance({
    triaName,
    payload,
    chain,
  }: {
    triaName: string;
    payload: Approve;
    chain: ChainData;
  }): Promise<CheckTokenAllowanceResponse>;
```

```typescript
export interface Approve {
  tokenAddress: string;
  amount: number;
  spender: string;
}
```

```typescript
export interface CheckTokenAllowanceResponse {
  success: boolean;
  allowance?: boolean;
  message?: string;
}
```

* Can be used to show Approve button or Swap button
* Can be used to check allowance for the <mark style="color:yellow;">pay token</mark> and then proceed to Approve or the Txn requested for (like Mint, Swap, etc)

</details>

<details>

<summary>Get Approve Fee</summary>

```typescript
getApproveFee({
    triaName,
    chain,
    payload,
  }: {
    triaName: string;
    chain: ChainData;
    payload: Approve;
  }): Promise<FeeResponse>
```

```typescript
export interface Approve {
  tokenAddress: string; // e.g. USDC token
  amount: number; // eg. 1 MATIC
  spender: string; // contract address approving for
}
```

</details>

<details>

<summary>Get Call Contract Fee</summary>

```typescript
getCallContractFee({
    triaName,
    chain,
    contractDetails,
  }: {
    triaName: string;
    chain: ChainData;
    contractDetails: ContractDetails;
  }): Promise<FeeResponse>;
```

```typescript
export interface ContractDetails {
  contractAddress: string;
  abi: Object[];
  functionName: string;
  args: [];
  value?: number; // e.g. 1, if 1 MATIC to transfer, and 0 if no native token to be paid needed, if paying in ERC20 token need not be specified, use approve function for the same
}
```

</details>

<details>

<summary>Get Send NFT Fee</summary>

```typescript
getSendNFTFee({
    chain,
    fromTriaName,
    recipientTriaName,
    nftDetails,
  }: {
    chain: ChainData;
    fromTriaName: string;
    recipientTriaName: string;
    nftDetails: NFTDetails;
  }): Promise<FeeResponse>
```

```typescript
interface NFTDetails {
  type: string; // ERC721 | ERC1155
  tokenAddress: string;  
  tokenId: string; 
  amount: number; // expect from FE hook // same as quantity
}
```

* Use tokenAddress and tokenId, to getNFTDetails from User Controller.

</details>

### Types

<details>

<summary>FeeResponse</summary>

```typescript
export type FeeResponse = {
  success: boolean;
  fee?: {
    eth: string;
    usd?: string;
    plaformFeeInPercent?: number;
    platformFeeInEth?: string;
    platformFeeInUsd?: string;
    totalInEth?: string;
    totalInUsd?: string;
  };
  message?: string;
  error?: any;
```

```json
// Example
{
  success: true,
  fee: { eth: '0.03473308532709981', usd: '0.025999068957661964' }
}
```

</details>

<details>

<summary>ChainData</summary>

```typescript
export type ChainData = {
  chainName?: string;
  customChain?: CustomChainData;
};

export type CustomChainData = {
  type: "EVM";
  chainId: number;
  rpcUrl: string;
  currencySymbol: string;
  currencyName?: string;
  chainName?: string;
  chainLogo?: string;
  explorerUrl?: string;
};
```

</details>


---

# Agent Instructions: 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:

```
GET https://docs-priv.tria.so/reference/onboarding-and-wallet-sdk/tria-sdk-web-internal/fee-controller.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
