libcardano-wallet
v3.0.2
Published
### Getting Started Install: ```bash npm install libcardano-wallet ``` or ```bash yarn add libcardano-wallet ```
Readme
libcardano-wallet
Getting Started
Install:
npm install libcardano-walletor
yarn add libcardano-walletBasic Classes/interfaces
- Cip30Interface : Cip-30 interface
- Cip30* : Cip-30 like interface, but returns Decoded objects instead of hex strings.
- Cip30Wrapper, Cip30ProviderWrapper : Helper classes to convert a
Cip30Interfaceinterface toCip30interface or vice versa.
Wallet Classes
- ShelleyWallet : Single address Wallet with payment key and optional(stake,drep keys)
- SimpleCip30Wallet : CIP-30 wallet that uses
ShelleyWalletfor keys and addresses - HdWallet : Work with wallet seed phrase, generate accounts, and create multiple
ShelleyWalletfrom accounts.
Usage Examples
Generate a simple Shelley wallet and derive addresses:
import { ShelleyWallet } from "libcardano-wallet";
const wallet = await ShelleyWallet.generate();
const paymentAddress = wallet.addressBech32(0); // 0=testnet, 1=mainnet
const stakeAddress = wallet.stakeAddrechBech32(0);
console.log({ paymentAddress, stakeAddress });Create a wallet from a mnemonic with the HD wallet helper:
import { HdWallet } from "libcardano-wallet";
const mnemonic =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
const hdWallet = await HdWallet.fromMnemonicString(mnemonic);
const account = await hdWallet.getAccount(0);
const wallet = await account.singleAddressWallet(0);
console.log(wallet.addressBech32(0));Use the CIP-30 wrapper with custom query/submit providers:
import { SimpleCip30Wallet } from "libcardano-wallet";
import type { QueryAPIProvider, SubmitAPIProvider } from "libcardano-wallet";
const queryProvider: QueryAPIProvider = {
async queryUTxOByAddress(address) {
return []; // fetch UTxOs from your backend or node
},
async queryUTxOByTxIn(_txIn) {
return [];
},
async queryProtocolParameters() {
throw new Error("Not implemented");
},
};
const submitProvider: SubmitAPIProvider = {
async submitTx(_tx) {
return "ok";
},
};
const cip30Wallet = await SimpleCip30Wallet.generate(queryProvider, submitProvider, 0);
const networkId = await cip30Wallet.getNetworkId();
const balance = await cip30Wallet.getBalance();
console.log({ networkId, balance: balance.toString() });