--- parent: build-apps.html targets: - en - ja # TODO: translate this page blurb: Build a graphical desktop wallet for the XRPL using JavaScript. --- # Build a Desktop Wallet in JavaScript This tutorial demonstrates how to build a desktop wallet for the XRP Ledger using the JavaScript programming language, the Electron Framework and various libraries. This application can be used as a starting point for building a more complex and powerful application, as a reference point for building comparable apps, or as a learning experience to better understand how to integrate XRP Ledger functionality into a larger project. ## Prerequisites To complete this tutorial, you should meet the following requirements: - You have [Node.js](https://nodejs.org/) 14+ installed. - You are somewhat familiar with modern JavaScript programming and have completed the [Get Started Using JavaScript tutorial](get-started-using-javascript.html). - You have at least some rough understanding of what the XRP Ledger, it's capabilities and of cryptocurrency in general. Ideally you have completed the [Basic XRPL guide](https://learn.xrpl.org/). ### Source Code You can find the complete source code for all of this tutorial's examples in the [code samples section of this website's repository]({{target.github_forkurl}}/tree/{{target.github_branch}}/content/_code-samples/build-a-wallet/desktop-js/). After a `npm install` in this directory you can run the application for each step as described in the `scripts` section of `package.json`, e.g, `npm run ledger-index`. **Caution:** As the source code is grouped into one folder for each step, you have to be careful should you copy-and-paste directly from there. Some shared imports and file operations have different directories in these examples. This goes for everything to do with `library`, `bootstrap`, and `WALLET_DIR`. ## Rationale This tutorial will take you through the process of creating a XRP Wallet application from scratch. Starting with a simple, "Hello World" like example with minimal functionality, we will step-by-step add more complex features. We will use the well-established [Electron Framework](https://www.electronjs.org/) to let us use JavaScript to write this desktop application. ## Goals At the end of this tutorial, you will have built a JavaScript Wallet application that looks something like this:  The look and feel of the user interface should be roughly the same regardless of operating system, as the Electron Framework allows us to write cross-platform applications that are styled with HTML and CSS just like a web-based application. The application we are going to build here will be capable of the following: - Showing updates to the XRP Ledger in real-time. - Viewing any XRP Ledger account's activity "read-only" including showing how much XRP was delivered by each transaction. - Sending [direct XRP payments](direct-xrp-payments.html), and providing feedback about the intended destination address, including: - Whether the intended destination already exists in the XRP Ledger, or the payment would have to fund its creation. - If the address doesn't want to receive XRP ([`DisallowXRP` flag](become-an-xrp-ledger-gateway.html#disallow-xrp) enabled). - If the address has a [verified domain name](https://xrpl.org/xrp-ledger-toml.html#account-verification) associated with it. The application in this tutorial _doesn't_ have the ability to send or trade [tokens](issued-currencies.html) or use other [payment types](payment-types.html) like [Escrow](https://xrpl.org/escrow.html) or [Payment Channels](https://xrpl.org/payment-channels.html). However, it provides a foundation that you can implement those and other features on top of. In addition to the above features, you'll also learn a bit about Events, IPC (inter-process-communication) and asynchronous (async) code in JavaScript. ## Steps ### 0. Project setup - Hello World 1. To initialize the project, create a package.json file with the following content: ```json { "name": "xrpl-javascript-desktop-wallet", "version": "1.0.0", "license": "MIT", "scripts": { "start": "electron ./index.js" }, "dependencies": { "async": "^3.2.4", "fernet": "^0.4.0", "node-fetch": "^2.6.9", "pbkdf2-hmac": "^1.1.0", "open": "^8.4.0", "toml": "^3.0.0", "xrpl": "^2.6.0" }, "devDependencies": { "electron": "22.3.2" } } ``` Here we define the libraries our application will use in the `dependencies` section as well as shortcuts for running our application in the `scripts` section. 2. After you create your package.json file, install those dependencies by running the following command: ```console npm install ``` This installs the Electron Framework, the xrpl.js client library and a couple of helpers we are going to need for our application to work. 3. In the root folder, create an `index.js` file with the following content: ```javascript const { app, BrowserWindow } = require('electron') const path = require('path') /** * This is our main function, it creates our application window, preloads the code we will need to communicate * between the renderer Process and the main Process, loads a layout and performs the main logic */ const createWindow = () => { // Creates the application window const appWindow = new BrowserWindow({ width: 1024, height: 768 }) // Loads a layout appWindow.loadFile(path.join(__dirname, 'view', 'template.html')) return appWindow } // Here we have to wait for the application to signal that it is ready // to execute our code. In this case we just create a main window. app.whenReady().then(() => { createWindow() }) ``` 4. Make a new folder named `view` in the root directory of the project. 5. Now, inside the `view` folder, add a `template.html` file with the following content: ```html