# Peer-to-Peer Payments

{% hint style="success" %}
Before we continue, please ensure that you have had a look at our [Supported Ethereum Chains](broken://pages/-MeAyzR2e2VKsOneDqAi), followed the steps in [Install Etherspot SDK](/getting-started/install-sdk.md) and how to [Bootstrap Etherspot SDK](/getting-started/bootstrap-etherspot-sdk.md). We're assuming that you have completed these steps before going forward.
{% endhint %}

In this example, we're going to show you how to transfer the funds using Peer-to-Peer Deposits

## :octagonal\_sign: Before we continue...

We're going to be using **two** Etherspot SDK instances here:

* A `ropsten` Etherspot SDK for our sender user wallet

:arrow\_upper\_right: We will use this instance to send our ETH from.

* A `ropsten` Etherspot SDK for our receiver user wallet

:arrow\_lower\_right: We will use this instance to receive our ETH on ropsten chain and ETH to pay the gas fees.

:warning: Make sure you've checked out [Supported Ethereum Chains](broken://pages/-MeAyzR2e2VKsOneDqAi) before you continue as we also show you the code to instantiate `ropsten` version of the SDK. **Remember to use different private keys or authentication for both SDK instances to get different Ethereum addresses on both Ropsten Testnet.**

## Getting started

For this guide, we're going to transfer ETH from one wallet to another wallet on the `Ropsten` network. To achieve this, we're going to send ETH from our `p2pPaymentDeposit` address linked to the user wallet to the another wallet on the `Ropsten` network.

We're going to assume that we're working with the following definitions:

```typescript
/**
* User Wallets
* - Network: Ropsten
* - const senderEtherspotUser
*
* - Network: Ropsten
* - const receiverEtherspotUser
*/
```

## Ensure Payment Deposit Address is funded

For this process to work, we need to make sure that the Payment Deposit have enough liquidity in them to facilitate the transfer to another wallet. We're going to be working with the `p2pDepositAddress` from our user wallet Etherspot SDKs. We can get this address as follows:

```javascript
const { p2pDepositAddress } = senderEtherspotUser.state;
```

The `p2pDepositAddress` exists purely to provide liquidity for other operations. Your `address` is unaffected.

We now need to add Test ETH from the [Ropsten Faucet](https://faucet.ropsten.be/). Please follow the instructions on the [Ropsten Faucet](https://faucet.ropsten.be/) website to receive Test ETH to the `p2pDepositAddress`.

Once you have received the Test ETH to the `p2pDepositAddress` in the `senderEtherspotUser` instance, we're ready to move on.

## Transfer Funds via Payment Deposit&#x20;

We need to transfer the desired amount of funds from our `p2pDepositAddress` in the `senderEtherspotUser` instance to the `p2pDepositAddress` in the `receiverEtherspotUser` instance

For this, we need to use the Etherspot SDK function `updateP2PPaymentChannel` to transfer from one Etherspot SDK to another with the following code:

```javascript
/**
* We're going to set 1 ETH as amount to be transferred.
*/
const amountToSend = ethers.utils.parseEther('1');

const output = await senderEtherspotUser.updateP2PPaymentChannel({
    recipient: receiverEtherspotUser.state.accountAddress,
    totalAmount: amountToSend, 
}).catch(console.error);

// This is the hash we will use in the next step.
console.log('Hash:', output.hash)
```

## Withdraw Funds from Payment Channel

To be able to withdraw the above `amountToSend` from the receiver Etherspot SDK, we need to perform a few final steps.&#x20;

{% hint style="info" %}
We're now working primarily with the `Ropsten` Receiver Etherspot SDK.
{% endhint %}

From the above `output` we need to get the hash to commit from the receiver SDK. This will allow us to withdraw the amount transferred. This can be done with the following:

```javascript
/*
* Remember to clear your batch and keep the house clean!
*/
await receiverEtherspotUser.clearGatewayBatch();

/**
* Next, commit the Payment Channel. The 
* batchCommitP2PPaymentChannel takes an object with two
* properties:
* - hash: the previously created Payment channel hash
* - deposit: 
* - - true: the exchange amount is transferred to the p2pDepositAddress.
* - - false: the exchange amount is transferred to the accountAddress
*/
await receiverEtherspotUser.batchCommitP2PPaymentChannel({
  hash: output.hash,
  deposit: true, // See notes above
}).catch(console.error);

/**
* Next, we estimate the cost of the transaction...
*/
await receiverEtherspotUser
 .estimateGatewayBatch();

/**
* And finally we submit this to the ETherspot Gateway.
*/
await receiverEtherspotUser
  .submitGatewayBatch();
```

{% hint style="warning" %}
Make sure that the receiver wallet has enough gas fees to pay on your p2pPaymentDepositAddress.
{% endhint %}

## :tada: Finished!


---

# 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://v1.etherspot.io/use-cases/peer-to-peer-payments.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.
