Throughout this tutorial we'll be making use of a little toolchain called StencilJs. It takes the best of modern frontend frameworks and pares everything back to small, blazing fast, 100% standards-based Web Components that run in every browser. Don’t worry if you've never heard of it: it's just TS (JS), SCSS (CSS) and JSX (HTML). You should be able to follow along just fine if you've ever built something with modern web dev tools.
We chose Stencil so you can learn by doing: it’s an easy way to create a web-based application, which means you can see the ins and outs of building a Bantu wallet start to finish. Bantu also has a suite of SDKs in various programming languages, so if Javascript isn’t your thing, you can follow along, and recreate the steps below using one of them.
To start the setup, open your terminal and initialize a new project.
npminitstencil
After running init you will be provided with a prompt to choose the type of project to start. While Stencil can be used to create entire apps, we’ll choose the component as we’ll just be dealing with modular components rather than building an entire application
? Pick a starter › - Use arrow-keys. Return to submit.ionic-pwaEverythingyouneedtobuildfast,productionreadyPWAsappMinimalstarterforbuildingaStencilapporwebsite❯componentCollectionofwebcomponentsthatcanbeusedanywhere
We’ll walk through the prompt, cd into the project and run npm i ; npm start
Now that our project is initialized, let’s take a look at the directory structure and familiarize ourselves with where things are and what roles they play.
We’re mostly interested in the src/ directory. The dist/ and www/ directories are outputs for compiled code. In the src/components/ directory you’ll see a my-component/ folder. We’re about to generate our own component, so go ahead and delete that folder. You can also nuke the utils/ directory as we won’t be covering tests in this tutorial. Now run:
$npmrungenerate
This will initialize a component generation script. Enter a name of bantu-wallet. Disable Spec Test and E2E Test as we’re not interested in those Stencil features today. Press Return and your component will generate and wire up.
Amazing! Just a few more setup bits and we can get coding. I don’t know about you but I prefer to style in SCSS rather than CSS so let’s get some modern CSS dev tools setup.
With that file saved, pop over to the src/components/wallet/ and rename the wallet.css to wallet.scss. While we’re here let’s go ahead and modify this new style file with some basic styling to put our project in a pretty place.
Before we update our wallet.tsx with this new stylesheet, note that we’re also importing a global stylesheet. Go ahead and create that file at the root of the src/ directory. So src/global/style.scss.
Save those style files and update the wallet.tsx to point to our new styles like so:
import { Component, h } from"@stencil/core";import*as StellarSdk from"stellar-sdk";@Component({ tag:"Bantu-wallet", styleUrl:"wallet.scss", shadow:true,})exportclassWallet {render() {return [ <h1> {!!StellarSdk ? "The StellarSdk is ready to rock 🤘":"Uh oh, the StellarSdk is missing 😱"}</h1>, ]; }}
You’ll notice we also include a few extra setup lines to get the StellarSdk loaded in and ready to use. Let’s ensure all those dependencies are loaded and ready to rock.
npmi-Dstellar-sdkjs-xdr
The last mod: point the src/index.html file to use this brand new component. Modify that file to match this.