How To Integrate Stellar Wallets Kit v2

Creit Tech Stellar Wallet Kit

This guide shows the fastest ways to add wallet connect + transaction signing to your app using Stellar Wallets Kit v2, with minimal code. It includes both React and a vanilla JS option via a bundled UMD script.

James On YouTube

Full examples

TL;DR

  • React/Node bundlers: install from JSR and import directly.
npx jsr add @creit-tech/stellar-wallets-kit
import { StellarWalletsKit } from "@creit-tech/stellar-wallets-kit/sdk";
  • Plain browser: drop in the prebuilt bundle
<script src="https://cdn.jsdelivr.net/gh/jamesbachini/Stellar-Wallets-Kit-Boilerplate@main/vanilla/stellar-kit-bundle/dist/wallet-kit-bundle.umd.js"></script>

React Setup

Install the libraries:

npx jsr add @creit-tech/stellar-wallets-kit 
npx npm i @stellar/stellar-sdk
  • Do this at app start, not on every render.
  • Default modules include the common wallets; you can add more if needed.

Import & initialize

import { StellarWalletsKit } from "@creit-tech/stellar-wallets-kit/sdk";
import { SwkAppDarkTheme, KitEventType } from "@creit-tech/stellar-wallets-kit/types";
import { defaultModules } from '@creit-tech/stellar-wallets-kit/modules/utils';
import * as StellarSdk from '@stellar/stellar-sdk';

StellarWalletsKit.init({
  theme: SwkAppDarkTheme,
  modules: defaultModules(),
});

Then add a div with the className buttonWrapper and load it up:

StellarWalletsKit.createButton(document.querySelector('#buttonWrapper'));
  • The kit renders a button that opens the connect wallet modal.

Then to sign transactions we can simply:

const {signedTxXdr} = await StellarWalletsKit.signTransaction(transaction.toXDR(), {
  networkPassphrase: StellarSdk.Networks.TESTNET,
  address,
});

Standard index.html

You can either user a prebuilt script or create your own locally.

<script src="https://cdn.jsdelivr.net/gh/jamesbachini/Stellar-Wallets-Kit-Boilerplate@main/vanilla/stellar-kit-bundle/dist/wallet-kit-bundle.umd.js"></script>

Alternatively to build your own:

To rebuild the bundle yourself, navigate to the stellar-kit-bundle directory in your terminal and run the following commands:

Fork and navigate into the bundle directory, ./vanilla/stellar-kit-bundle
Then check dependency versions and run these commands to rebuild.

cd stellar-kit-bundle
npm install
npm run build

This will use Vite to create a new wallet-kit-bundle.umd.js file in the /vanilla/stellar-kit-bundle/dist directory, which can be imported into the index.html file or anywhere else.

From there the functionality is identical to the react instructions above.

Full examples


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

, , , , ,

by