# BiDirectionalPaymentChannel

## Overview

The `BiDirectionalPaymentChannel` contract is designed to manage a two-way payment channel between two parties.&#x20;

This type of channel allows these parties to conduct numerous transactions with each other off-chain, with the final settlement occurring on the Ethereum blockchain.

The primary advantage of this approach is the significant reduction in transaction fees and improved efficiency, as only two transactions (channel opening and closing) are recorded on the blockchain, regardless of the number of off-chain transactions conducted.

## Methods

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

Checks whether the provided signatures are valid for the given contract state (balances and nonce).

### Parameters

| Name          | Type                | Description                                       |
| ------------- | ------------------- | ------------------------------------------------- |
| `_signatures` | `bytes[2] memory`   | Array of cryptographic signatures from the users. |
| `_contract`   | `address`           | Address of this contract.                         |
| `_signers`    | `address[2] memory` | Array of addresses of the signers.                |
| `_balances`   | `uint[2] memory`    | Proposed balances of the users in the channel.    |
| `_nonce`      | `uint`              | Nonce associated with the current state.          |

### Returns

| Name | Type   | Description                                                                        |
| ---- | ------ | ---------------------------------------------------------------------------------- |
| -    | `bool` | Returns `true` if the signatures are valid for the given state, otherwise `false`. |

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

Allows a user to propose a new state (balances and nonce) for the channel, secured by their signatures.

### Parameters

| Name          | Type              | Description                                                         |
| ------------- | ----------------- | ------------------------------------------------------------------- |
| `_balances`   | `uint[2] memory`  | Proposed balances of the users in the challenge.                    |
| `_nonce`      | `uint`            | Nonce associated with the challenge state.                          |
| `_signatures` | `bytes[2] memory` | Array of cryptographic signatures from the users for the challenge. |

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

Enables a user to withdraw their balance from the contract after the challenge period has expired.


---

# 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/bidirectionalpaymentchannel.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.
