/cardano-wallet-interface

a package that makes easier to interact with wallets on cardano

Primary LanguageJavaScriptMIT LicenseMIT

cardano-wallet-interface

brought to you by Harmonic Pool

Thank you

This softweare exists thanks to Harmonic delegators an supporters

How can I support?

  • delegate ADA to Harmonic Pool
  • donate ADA to : addr1qxm09exmyl04yhh67rvvmp2zauq32p8g7v60wtv03ved7t8h2y992ly7znq5q8ckurcpum0dc8kaunpkysnlnzzhw0pqd875p8
  • contribute building this repository
  • contribute building a greather Cardano with any repository of Harmonic Pool

Contents

Installation

run the following in your project directory

npm install https://github.com/HarmonicPool/cardano-wallet-interface

supported wallets

here's a list of supported wallet, if you notice a Cardano wallet that support dApp connector is missing, feel free to send a mail here

Usage

basic usage

access a generic wallet

let Typhon = undefined;
const ITyphon = Wallet.getInterface( Wallet.Names.Typhon );

if( 
    ITyphon.isInjected() // equivalent to ```Wallet.has( Wallet.Names.Typhon )```
)
{
    if(
        ITyphon.isAviable() // if enabled before returns true, no need to perform async calls
    )
    {
        Typhon = Wallet.Typhon; // Wallet.get( Wallet.Names.Typhon ) will do the same
    }
}
else // async code needed
{
    if(
        await ITyphon.isEnabled() // @returns {Promise<boolean>} as per CIP0030 definition
    )
    {
        Typhon = Wallet.Typhon; // same as before
    }
    else
    {
        await Wallet.enable( Wallet.Names.Typhon ); // makes the object aviable
        Typhon = Wallet.Typhon; // same as before
    }
}
simple delegation

NOTE: every other wallet will work the same way, just change the name (eg. Nami -> CCVault )

/*... other imports ...*/
import Wallet from "@harmonicpool/cardano-wallet-interface";

/*...*/

if( Wallet.has( Wallet.Names.Nami ) )
{
    if( !await Wallet.isEnabled( Wallet.Names.Nami ) )
    {
        Wallet.enable( Wallet.Names.Nami )
        .then(
            () => {
                Wallet.Nami.delegateTo(
                    "<your pool id>",
                    "<your blockforst api key>"
                );
            }
        );
    }
    else
    {
        Wallet.Nami.delegateTo(
            "<your pool id>",
            "<your blockforst api key>"
        );
    }
}

/*...*/

have a look at documentation/examples/Wallets iteration.md to understand how to generalize the process for more wallets

other examples

check the documentation/examples folder for more

Documentation

a more in depth documentation can be found in the documentation folder