# Escrow

## Overview

The `Escrow` contract is designed to securely manage the escrow process for various types of assets including ERC-20 tokens, Ether, and ERC-721 (NFT) tokens.&#x20;

It acts as an intermediary to hold assets until predefined conditions are met, providing a trustless mechanism for transactions between parties.

## Methods

## <mark style="color:blue;">`acceptToken`</mark>

Accepts ERC-20 tokens into escrow.

### Parameters

| **Parameter**  | **Type**  | **Description**                             |
| -------------- | --------- | ------------------------------------------- |
| `tokenAddress` | `address` | Address of the ERC-20 token.                |
| `_amount`      | `uint256` | Amount of tokens to be escrowed.            |
| `_endTime`     | `uint256` | Timestamp when the escrow will be unlocked. |

### Returns

| **Return** | **Type**  | **Description**                                   |
| ---------- | --------- | ------------------------------------------------- |
| `balance`  | `uint256` | Remaining balance of the sender post-transaction. |

## <mark style="color:blue;">`acceptEth`</mark>

Accepts Ether into escrow.

### Parameters

| **Parameter** | **Type**  | **Description**                             |
| ------------- | --------- | ------------------------------------------- |
| `_endTime`    | `uint256` | Timestamp when the escrow will be unlocked. |

### Returns

| **Return** | **Type**  | **Description**                       |
| ---------- | --------- | ------------------------------------- |
| `value`    | `uint256` | Amount of Ether sent to the contract. |

## <mark style="color:blue;">`tokenTransaction`</mark>

Retrieves the current state of an ERC-20 token transaction in escrow.

### Parameters

| **Parameter**  | **Type**  | **Description**              |
| -------------- | --------- | ---------------------------- |
| `tokenAddress` | `address` | Address of the ERC-20 token. |

### Returns

| **Return** | **Type**                         | **Description**                                     |
| ---------- | -------------------------------- | --------------------------------------------------- |
| Tuple      | `(uint256, bool, bool, uint256)` | Amount, lock status, spent status, and mature time. |

## <mark style="color:blue;">`ethTransacton`</mark>

Retrieves the current state of an Ether transaction in escrow.

### Returns

| **Return** | **Type**                         | **Description**                                     |
| ---------- | -------------------------------- | --------------------------------------------------- |
| Tuple      | `(uint256, bool, bool, uint256)` | Amount, lock status, spent status, and mature time. |

## <mark style="color:blue;">`ethRelease`</mark>

Admin function to unlock Ether in escrow.

### Parameters

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |

## <mark style="color:blue;">`ethWithdraw`</mark>

Allows the seller to withdraw unlocked Ether.

### Returns

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |

## <mark style="color:blue;">`tokenRelease`</mark>

Admin function to unlock ERC-20 tokens in escrow.

### Parameters

| **Parameter**  | **Type**  | **Description**              |
| -------------- | --------- | ---------------------------- |
| `tokenAddress` | `address` | Address of the ERC-20 token. |

### Returns

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |

## <mark style="color:blue;">`tokenWithdraw`</mark>

Allows the seller to withdraw unlocked ERC-20 tokens.

### Parameters

| **Parameter**  | **Type**  | **Description**              |
| -------------- | --------- | ---------------------------- |
| `tokenAddress` | `address` | Address of the ERC-20 token. |

### Returns

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |

## <mark style="color:blue;">`acceptNFT`</mark>

Accepts an ERC-721 token into escrow.

### Parameters

| **Parameter**   | **Type**  | **Description**                             |
| --------------- | --------- | ------------------------------------------- |
| `tokenContract` | `address` | Address of the ERC-721 token contract.      |
| `tokenId`       | `uint256` | ID of the token.                            |
| `_endTime`      | `uint256` | Timestamp when the escrow will be unlocked. |

### Returns

| **Return** | **Type**  | **Description**           |
| ---------- | --------- | ------------------------- |
| `tokenId`  | `uint256` | ID of the accepted token. |

## <mark style="color:blue;">`nftTransactions`</mark>

Retrieves current state of transactions in escrow for a specific ERC-721 token contract.

### Parameters

| **Parameter**   | **Type**  | **Description**                        |
| --------------- | --------- | -------------------------------------- |
| `tokenContract` | `address` | Address of the ERC-721 token contract. |

### Returns

| **Return**     | **Type**           | **Description**                        |
| -------------- | ------------------ | -------------------------------------- |
| `transactions` | `NFTTransaction[]` | An array of NFTTransaction structures. |

## <mark style="color:blue;">`nftRelease`</mark>

Admin function to unlock an ERC-721 token in escrow.

### Parameters

| **Parameter**   | **Type**  | **Description**                        |
| --------------- | --------- | -------------------------------------- |
| `tokenContract` | `address` | Address of the ERC-721 token contract. |
| `tokenIndex`    | `uint256` | Index of the token in the escrow.      |

### Returns

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |

## <mark style="color:blue;">`nftWithdraw`</mark>

Allows the seller to withdraw an unlocked ERC-721 token.

### Parameters

| **Parameter**   | **Type**  | **Description**                        |
| --------------- | --------- | -------------------------------------- |
| `tokenContract` | `address` | Address of the ERC-721 token contract. |
| `tokenIndex`    | `uint256` | Index of the token in the escrow.      |

### Returns

| **Return** | **Type** | **Description**             |
| ---------- | -------- | --------------------------- |
| `success`  | `bool`   | Returns true if successful. |


---

# 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.volary.io/template-library/smart-contracts/escrow.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.
