npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wingriders/cab

v2.0.30

Published

CAB is a library to help with development of Cardano apps for browser and Node.js

Downloads

43

Readme

@wingriders/cab

CAB (Cardano Application Backend) is a library, that helps you with development of Cardano apps for browser and Node.js. It can help with:

  • Wallet and Account management
  • Ability to define custom data sources for blockchain data
  • Crypto helpers to generate new mnemonics and derive public and private keys
  • CIP-30 dApp connector helpers
  • A transaction planner with Plutus, metadata support and automatic UTxO selection

Get started

yarn

yarn add @wingriders/cab

npm

npm i @wingriders/cab

Development roadmap

  • [ ] Add documentation
  • [ ] Add support for Plutus V2
  • [ ] Refine transaction planner
  • [ ] Open-source data providers
  • [ ] Clean up helpers and error reporting
  • [ ] Refine tests
  • [ ] ES Modules support

Basic usage

CAB has many functionalities, which we are working on documentating. These are just basic examples of how you may use the library.

Account management

An account belongs to a wallet, that is defined mainly by the wallet's secret key - mnemonic.

import {NETWORKS} from '@wingriders/cab/constants'
import {JsCryptoProvider, mnemonicToWalletSecretDef} from '@wingriders/cab/crypto'
import {NetworkName} from '@wingriders/cab/types/network'
import {Wallet} from '@wingriders/cab/wallet'

// Here we assume the `onChainDataProvider`, `ledgerStateProvider` and
// `submitTxProvider` are already defined. We are working on open-source
// implementation of these. In the meantime you can bring your own that
// adheres to the defined interfaces - see src/dataProviders/types.ts

const wallet = new Wallet({
  onChainDataProvider,
  ledgerStateDataProvider,
  submitTxProvider,
  cryptoProvider: new JsCryptoProvider({
    // Here we assume the mnemonic is in a variable called `secretMnemonic`
    // for example loaded from the environment variables
    walletSecretDef: await mnemonicToWalletSecretDef(secretMnemonic),
    network: NETWORKS[NetworkName.MAINNET],
    config: {
      shouldExportPubKeyBulk: true,
    },
  }),
  config: {
    shouldExportPubKeyBulk: true,
    gapLimit: 20,
  },
})

// Load the first account - account with index 0
await wallet.getAccountManager().addAccounts([0])

// Get the first account
const account = wallet.getAccountManager().getAccount(0)

Transaction planner

To create a basic transaction for sending 10 ADA to Alice, from account we loaded in previous step

import {getTxPlan} from '@wingriders/cab/ledger/transaction'
import {TxPlanArgs} from '@wingriders/cab/types'

// Obtain the protocol parameters from your ledger state provider
const protocolParameters = await ledgerStateProvider.getProtocolParameters()

// Define the plan of the transaction
const txPlanArgs: TxPlanArgs = {
  planId: 'send-ada-to-Alice',
  outputs: [
    {
      address: "addr1z8n...u6v8",
      coins: new Lovelace(10_000_000) as Lovelace,
    },
  ],
  protocolParameters,
}

// Try to create the transaction plan, using available utxos in your account
// and send the change to your account's change address
const txPlanResult = getTxPlan(txPlanArgs, account.getUtxos(), account.getChangeAddress())

if (!txPlanResult.success) {
  // If it failed report the reasons why, for avaible fiels refer to the
  // `TxPlanResult` type
  return
}

// Sign the transaction using your account and submit the transaction
// via your wallet's SubmitTxProvider
const txAux = prepareTxAux(txPlanResult.txPlan)
const signedTx = await account.signTxAux(txAux)
await wallet.submitTx(signedTx)

// If needed feel free to track your transaction submission here