# BI-DIRECTIONAL PAYMENT

### DESCRIPTION

The Bi-Directional Payment Channel contract enables the creation and management of a bi-directional payment channel between two users. It allows users to open a channel by funding a multi-signature wallet, precomputing the payment channel address, and exchanging signatures of initial balances. Users can then update channel balances by providing updated balances and signatures. In case of disagreement on the final balances, users can initiate the challenge exit process. Once the challenge period expires, users can withdraw their funds from the channel.

### FUNCTIONS

1. **challengeExit():** This function allows a user to initiate the challenge exit process by providing updated balances and signatures. It verifies the signatures, updates the balances, increments the nonce, and extends the expiration time. This function is used when Alice and Bob do not agree on the final balances and want to close the channel forcibly.
2. **withdraw():** This function allows a user to withdraw their funds from the channel after the challenge period has expired. It transfers the user's balance to their address.
3. **balances()**
4. **challengePeriod()**
5. **exipresAt()**
6. **isUser()**
7. **nonce()**
8. **users()**

### EXTRA PARAMETERS

**Contract Level:** Medium

**Utility Tags:** Payment Channel, Multi-Sign, Challenge Exit, Balance Update

1. **Users:address\[2]**
2. **Balances: Integer2]]**
3. **expiresAt: Integer**
4. **challengePeriod: Integer**

### USES

1. **Off-Chain Transactions:** The contract facilitates off-chain transactions between two users by allowing them to update balances and settle the channel on-chain only when necessary. This reduces transaction costs and increases scalability.
2. **Secure Channel Closure:** The contract provides a mechanism for users to close the payment channel securely, even if they do not agree on the final balances. The challenge exit process ensures that users can withdraw their funds after the challenge period expires.
3. **Trustless Interactions:** The use of signatures and verifications in the contract ensures trustless interactions between users. Each user can independently verify the validity of the other user's actions and ensure the integrity of the channel.


---

# 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://sinqlarity.gitbook.io/sinqlarity-docs/contract-details/bi-directional-payment.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.
