# Send Hbar

The following sample will show you how to prompt a user to send Hbar. Useful to make a payment. We will first generate a request for the end user with transaction's details. Once validated, you will get notified about transaction's status.

## Prerequisites: <a href="#pre-requisites" id="pre-requisites"></a>

{% content-ref url="/pages/-Mg56\_a4eJ5VygETYHMC" %}
[Getting started](/xact/sdk/javascript/getting-started.md)
{% endcontent-ref %}

## Step 1: Import the following modules

Let's continue building on the *index.js* from the previous example ([Environment Set-up](/xact/sdk/javascript/getting-started.md#step-1-set-up-your-node-js-environment)) and add the following modules:

```typescript
const { Client, MiddleManFeesType } = require("@xact-wallet-sdk/client");
require("dotenv").config();
```

## Step 2: Get Xact Fees

Before initializing the payment, you probably need to get the fees from our service. For that matter, we will simply need to specify the amount of the transaction

```typescript
const hbarAmount = 100;
const xactFees = await client.getXactFeesPayment(hbarAmount);
```

{% hint style="info" %}
The amount must be specified in Hbar.&#x20;
{% endhint %}

## Step 3: Initializing a payment

### 1.1 From an account to an account

When initializing a payment, a request is sent to the end user for authorization.

```typescript
/* Update the fields with your informations */
const hbarAmount = 100;
const toAccountId = '';
const fromAccountId = '';

/* Request for payment */
await client.pay({toAccountId, fromAccountId, hbarAmount});
```

### 1.2 From an account to an account and to a middleman

You can also add **middleman account to pay** throughout the process. Middleman take fees, those fees can be a fixed amount of HBAR (`MiddleManFeesType.HBAR`) or a percent (`MiddleManFeesType.PERCENT`) of the `hbarAmount`, the type is defined in the `middleManTypeOfFees` property.

{% hint style="info" %}
Payer account `fromAccountId` will pay Hedera Hashgraph network fees for each transaction. If there is three middlemen and one recipient, payer will pay four transactions fees. **Note that middle men fees are taken from the hbarAmount**
{% endhint %}

```typescript
/* Update the fields with your informations */
const hbarAmount = 100;
const toAccountId = '';
const fromAccountId = '';
const middleManAccountId = ''
const middleManAccountId2 = '';

/* Add 3rd-party payment */
const middleMen = [
    {
        middleManAccountId,
        middleManTypeOfFees: MiddleManFeesType.HBAR,
        middleManFees: 10
    },
     {
        middleManAccountId2,
        middleManTypeOfFees: MiddleManFeesType.PERCENT,
        middleManFees: 2
    },
    
];

/* Request for payment with tiers */
await client.pay({toAccountId, fromAccountId, hbarAmount, middleMen});
```

## Step 4: Listen to new Payments

Finally get notified when a new payment has been done successfully!

```typescript
/* Subscribe to new Payments */
client.paymentValidation().subscribe(payment => {
    console.log('new Payment', payment);
});
```

⭐ Congratulations! You have successfully completed a payment process

## Code Check ✅

Your *index.js* file should look like this:

{% code title="index.js" %}

```typescript
const { Client, TierFeesType } = require("@xact-wallet-sdk/client");
require("dotenv").config();

async function pay() {

    //Grab your api key from your .env file
    const apiKey = process.env.API_KEY;


    // If we weren't able to grab it, we should throw a new error
    if (apiKey == null) {
        throw new Error("Environment variables API_KEY must be present");
    }
    /* Create a new instance of Client */
    const client = new Client({apiKey});
    
    /* Init the connexion */
    await client.initConnexion();
    
    /* Update the fields with your informations */
    const hbarAmount = 100;
    const toAccountId = '';
    const fromAccountId = '';
    const middleManAccountId = ''
    const middleManAccountId2 = '';
    
    /* Add tiers payment */
    const middleMen = [
        {
            middleManAccountId,
            middleManTypeOfFees: MiddleManFeesType.HBAR,
            middleManFees: 10
        },
         {
            middleManAccountId: middleManAccountId2,
            middleManTypeOfFees: MiddleManFeesType.PERCENT,
            middleManFees: 2
        },
        
    ];
    
    /* Get Xact Fees */
    const xactFees = await this.client.getXactFeesPayment(100);
    
    /* Request for payment */
    await client.pay({toAccountId, fromAccountId, hbarAmount, middleMen});
    
    /* Listen for Payment's success */
    client.paymentValidation().subscribe(payment => {
        console.log('new Payment', payment);
    });
}

pay();
```

{% endcode %}


---

# 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://xact.gitbook.io/xact/sdk/javascript/pay.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.
