Skip to main content

Usage of the kit

The StellarWalletsKit class

The first step will be creating a new instance from the main class, you should only create one instance in the whole lifecycle of the user visit in order to avoid unexpected results.

import {
StellarWalletsKit,
WalletNetwork,
allowAllModules,
XBULL_ID
} from '@creit.tech/stellar-wallets-kit';

const kit: StellarWalletsKit = new StellarWalletsKit({
network: WalletNetwork.TESTNET,
selectedWalletId: XBULL_ID,
modules: allowAllModules(),
});

The allowAllModules() function doesn't import those modules where you need to provide a configuration (like WalletConnect), you will need to add them manually so check the folder src/modules to know all the available modules.

If you want to specify only the wallets you want to support, you can start the kit with only those by sending the modules to the constructor like this:

import {
FreighterModule,
StellarWalletsKit,
WalletNetwork,
XBULL_ID,
xBullModule
} from '@creit.tech/stellar-wallets-kit';

const kit: StellarWalletsKit = new StellarWalletsKit({
network: WalletNetwork.TESTNET,
selectedWalletId: XBULL_ID,
modules: [
new xBullModule(),
new FreighterModule(),
]
});

Request the public key and sign transactions

Each wallet has its own way when it comes to both requesting the public key and signing a transaction. Using this kit you can do both actions with a unified API:

const { address } = await kit.getAddress();
// AND THEN
const { signedTxXdr } = await kit.signTransaction('XDR_HERE', {
address,
networkPassphrase: WalletNetwork.PUBLIC
});

Both methods will trigger the action using the wallet you have set before calling those methods.

Extra methods

There will be moments where you would like to change certain parameters from the kit like the selected wallet, the network, etc... or maybe listening when a WalletConnect session was removed. These methods will help you in those situations:

Set the target wallet

await kit.setWallet(XBULL_ID)

Set the target network

await kit.setNetwork(WalletNetwork.TESTNET);