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:
Getting startedStep 1: Import the following modules
Let's continue building on the index.js from the previous example (Environment Set-up) and add the following modules:
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
const hbarAmount = 100;
const xactFees = await client.getXactFeesPayment(hbarAmount);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.
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.
Step 4: Listen to new Payments
Finally get notified when a new payment has been done successfully!
⭐ Congratulations! You have successfully completed a payment process
Code Check ✅
Your index.js file should look like this:
Last updated