@koralabs/cardano-wallets
v0.4.0
Published
Library for connecting cardano wallets in the browser using CIP-30
Downloads
335
Readme
Cardano Wallets
Library for connecting cardano dApps to wallet browser extensions using CIP-30.
Installation
Using npm:
npm install @koralabs/cardano-wallets
Usage:
Connecting to a wallet
import CardanoWallets from '@koralabs/cardano-wallets';
const walletKey = 'nami';
await CardanoWallets.connect(walletKey);
// Verify wallet's network is mainnet
const isMainnet = await CardanoWallets.isMainnet();
if (!isMainnet) {
throw new Error('Wallet must be in Mainnet');
}
// verify wallet balance
const minimumBalanceNeeded = 100;
await CardanoWallets.verifyBalance(minimumBalanceNeeded);
Getting policy assets
import CardanoWallets from '@koralabs/cardano-wallets';
const walletKey = 'nami';
await CardanoWallets.connect(walletKey);
const utxos = await CardanoWallets.getUtxos();
const builtUtxos = CardanoWallets.buildUtxos(utxos);
const policyId = "some_policy_id";
const assets = builtUtxos.reduce<{
name: string;
hex: string;
policyId: string;
}[]>((agg, utxo) => {
const { assets } = utxo;
for (let i = 0; i < assets.length; i++) {
const asset = assets[i];
if (asset.policyId === policyId) {
agg.push(asset);
}
}
return agg;
}, []);