Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cardano-foundation/cardano-connect-with-wallet

Package Overview
Dependencies
Maintainers
7
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardano-foundation/cardano-connect-with-wallet

This package aims to provide useful hooks and React components to simplify the cardano dapp integration

  • 0.2.9
  • latest
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

Cardano Connect with Wallet - React

Tests Release conventionalcommits Discord

This repository aims to provide useful hooks and React components to simplify the cardano dapp integration e.g. to connect browser wallets, fetch addresses and provide signing (CIP 8, CIP 30).

🚀 Getting Started

npm i @cardano-foundation/cardano-connect-with-wallet

React

For more detailed information and usage examples, please refer to the storybook playground.

🪝 Hooks

useCardano allows you to interact with wallets supporting CIP 30 and CIP 8. It's a useful wrapper of the window.cardano object and manages state information within the local storage.

import { useCardano } from '@cardano-foundation/cardano-connect-with-wallet';

const YourGreatDApp = (props) => {
    const { 
        isEnabled,
        isConnected,
        enabledWallet,
        stakeAddress,
        signMessage,
        connect,
        disconnect 
    } = useCardano();

    const onConnect = () => alert('Successfully connected!');

    return (
        <>
            { isConnected ?
                <span>{ stakeAddress }</span> :
                <button
                    onClick={() => connect(
                        'wallet_name_with_cip30_support',
                        onConnect
                    )}>Connect</button>
            }
            <NiceOtherComponents>...</NiceOtherComponents>
        </>
    )
}

🎨 Components

This library provides ready to use Components for connecting, disconnect and signing.

import { ConnectWalletList, ConnectWalletButton } from '@cardano-foundation/cardano-connect-with-wallet';


<ConnectWalletList
    borderRadius={15}
    gap={12}
    primaryColor="#0538AF"
    onConnect={onConnectWallet}
    customCSS={`
        font-family: Helvetica Light,sans-serif;
        font-size: 0.875rem;
        font-weight: 700;
        width: 164px;
        & > span { padding: 5px 16px; }
    `}
/>

<ConnectWalletButton
    message="Please sign Augusta Ada King, Countess of Lovelace"
    onSignMessage={onSign}
    onConnect={onConnect}
/>

ℹ️ SSR with Next.js

This library tries to get access to the window object which is not present on the server-side when Next.js pre-renders the page. The solution here is to use dynamic imports. One should use dynamic imports for both the components and hooks.

An example of using the ConnectWalletList with Next.js could look like the following:

const ConnectWalletList = dynamic(
  () =>
    import('@cardano-foundation/cardano-connect-with-wallet').then(
      (mod) => mod.ConnectWalletList
    ),
  {
    ssr: false,
  }
);

💪 Contributing

Please have a look at our contributing infos to become familiar with our guidelines. There is also a short description for our development setup as we use Storybook for testing, playing around and for supporting the development process.

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc