Cross-chain Token Purchase
This page describes the repository with an example of the cross-chain token purchase.
Last updated
This page describes the repository with an example of the cross-chain token purchase.
Last updated
In this example, we will take a look at a simple project which can be found here: GitHub
This application is extremely simple, to demonstrate how easy it is to integrate XPay. Assuming that the Dapp already has integration with the web3 wallet provider we will focus more on the XPay. For this example, the application is using RainboKit to connect the wallet. In the next section let's take a look at the XPay integration.
To run the demo locally clone the repository, create a .env
file by coping the .env.sample
, and set the variables VITE_INTEGRATOR_ID
(the framework requires the prefix VITE_). If you don't have an integrator Id please Apply Here.
Then using the npm package manager run the following command
After installing the dependencies start the dev server
In this demo, we use just one function from XPay, openTransactionModal
.
Here is the function call from the project
Here we defined the chain
and token
that users will be able to buy as well as the integratorId
. This function opens a modal for the user where they will be able to select the source chain and token for the transaction.
Once the user approves the swap form, the modal will move to the execution view. The transactions contain optional approve and swap transactions which need to be signed by the user.
After the swap transaction was confirmed on the source blockchain the cross-chain swap is in motion and we can monitor the transaction progress. Once the transaction is being delivered a notification will appear in the corner of the browser.
After the cross-chain message is delivered and executed the notification will change to green and disappear.