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

@civic/multichain-connect-react-solana-wallet-adapter

v0.2.2

Published

A multichain wallet connect library

Downloads

1,765

Readme

Multichain Connect React

Overview

The Multichain Connect React library is a versatile TypeScript library that simplifies wallet integration for decentralized applications (dApps) by providing a unified interface for connecting to different wallets across multiple blockchains. It includes a React interface for seamless integration with React-based projects. The library allows developers to easily add new wallet adapters and supports customizable chain configurations. Once production ready, the library will consider porting over to the following Wallet Standard React interface.

Core Functionality:

The library offers a multi-chain wallet adapter that serves as a bridge between dApps and various wallet providers. It provides a standardized API for wallet interactions, enabling users to connect their preferred wallet across different blockchains seamlessly.

React Interface:

Includes a pre-built React interface that simplifies the integration of wallet functionality into React applications. This interface offers intuitive components and hooks that developers can leverage to handle wallet interactions and user authentication with ease.

Chain Customization:

Developers can specify the chains they want to support within their application. Multichain Connect React allows for easy configuration of supported chains, such as EVM supported chains, Solana, etc. This flexibility enables dApps to cater to specific blockchain ecosystems while maintaining a consistent user experience.

Extensibility:

The library is designed with extensibility in mind. It provides a straightforward mechanism for adding additional wallet adapters, allowing developers to expand the range of supported wallets easily. By following the provided adapter interface and guidelines, new wallet integrations can be seamlessly incorporated into the existing framework. This also gives the user flexibility in which wallet adapters they choose to use.

Installation

To use the MultiChain Wallet Connect React components, follow these steps:

  1. Install the package using npm:

    npm install @civic/multichain-connect-react-core @civic/multichain-connect-react-solana-wallet-adapter @civic/multichain-connect-react-rainbowkit-wallet-adapter wagmi/providers/public @solana/web3.js

    or using Yarn:

    yarn add @civic/multichain-connect-react-core @civic/multichain-connect-react-solana-wallet-adapter @civic/multichain-connect-react-rainbowkit-wallet-adapter wagmi/providers/public @solana/web3.js
  2. Import the necessary components and dependencies into your code:

    import {
      MultichainWalletProvider,
      MultichainConnectButton,
    } from "@civic/multichain-connect-react-core";
    import {
      Chain as SolanaChain,
      SolanaWalletAdapterConfig,
    } from "@civic/multichain-connect-react-solana-wallet-adapter";
    import {
      Chain as EthereumChain,
      RainbowkitConfig,
    } from "@civic/multichain-connect-react-rainbowkit-wallet-adapter";
    import { publicProvider } from "wagmi/providers/public";
    import { Connection } from "@solana/web3.js";
    import {
      mainnet,
      goerli,
      polygon,
      arbitrum,
      arbitrumGoerli,
      polygonMumbai,
    } from "wagmi/chains";

    Note: Make sure you have the required dependencies installed, including @solana/web3.js.

Usage

To use the MultiChain Wallet Connect React components, follow these steps:

  1. Wrap your application or relevant components with the MultichainWalletProvider component:

    <MultichainWalletProvider>
      {/* Your application components */}
    </MultichainWalletProvider>
  2. Configure the Solana wallet adapter by using the SolanaWalletAdapterConfig component within the MultichainWalletProvider:

    const solanaChains = [
      { name: "Solana", rpcEndpoint: clusterEndpoint("mainnet-beta") },
    ];
    const solanaTestChains = [
      { name: "Solana Devnet", rpcEndpoint: clusterEndpoint("devnet") },
    ];
    
    <MultichainWalletProvider>
      <SolanaWalletAdapterConfig
        chains={solanaChains}
        testnetChains={solanaTestChains} // These will display unde the testnets tab
      >
        {/* Your application components */}
      </SolanaWalletAdapterConfig>
    </MultichainWalletProvider>;
  3. Configure the Rainbowkit wallet adapter by using the RainbowkitConfig component within the MultichainWalletProvider:

    const evmChains = [polygon, mainnet];
    const evmTestChains = [polygonMumbai, goerli];
    const initialChain = { ...polygonMumbai, type: SupportedChains.Ethereum };
    
    <MultichainWalletProvider initialChain={initialChain}>
      <RainbowkitConfig
        chains={evmChains}
        testnetChains={evmTestChains} // These will display unde the testnets tab
        theme={myCustomTheme}
        providers={[publicProvider()]}
        options={{
          // Rainbowkit relies on WalletConnect which now needs to obtain a projectId from WalletConnect Cloud.
          walletConnectProjectId: "*YOUR WALLET CONNECT PROJECT ID*",
        }}
      >
        {/* Your application components */}
      </RainbowkitConfig>
    </MultichainWalletProvider>;

    Replace initialChain, myCustomTheme, and publicProvider() with the appropriate values and configurations for your project.

  4. Use the MultichainConnectButton component to display the wallet connection button in your application:

    <MultichainWalletProvider>
      <RainbowkitConfig>
        <SolanaWalletAdapterConfig>
          <MultichainConnectButton />
        </SolanaWalletAdapterConfig>
      </RainbowkitConfig>
    </MultichainWalletProvider>

Customize the placement and appearance of the button as needed in your application's layout.

That's it! You can now integrate MultiChain Wallet Connect React components into your application to enable wallet connectivity and interactions with Solana and Ethereum-based chains.

Architecture

The architecture can be viewed here.

sequenceDiagram
    User->>UI: Open dApp
    UI->>MultiChainConnect: Initialize with supported chains
    MultiChainConnect->>WalletAdapter: Initialize the Wallet Adapter with wallets that conform to the wallet standard
    MultiChainConnect->>UI: Show connect button
    User->>MultiChainConnect: Connect
    MultiChainConnect->>User: Open modal with supported chains
    User->>MultiChainConnect: Select chain
    MultiChainConnect->>MultiChainConnect: Store the selected chain
    MultiChainConnect->>WalletAdapter: Launch selected chain's Wallet Adapter
    WalletAdapter->>User: Return a list of available wallets the user can connect with
    User->>WalletAdapter: Select wallet
    WalletAdapter->>MultiChainConnect: Return connected Wallet
    MultiChainConnect->>MultiChainConnect: Store the connected Wallet
    MultiChainConnect->>WalletAdapter: Get connect UI for showing the connected wallet
    WalletAdapter->>UI: Show UI for connected wallet and button for disconnecting wallet

Custom button

  1. Creating your own button with custom styling:
import React from "react";
import styled from "styled-components";
import {
  MultichainConnectedButton,
  useWallet,
  useModal,
} from "@civic/multichain-connect-react";

// Styled component named StyledButton
const StyledButton = styled.button`
  display: inline-block;
  border-radius: 20px;
  padding: 0.5rem 0;
  margin: 0.5rem 1rem;
  width: 11rem;
  border: 2px solid black;
  background: white;
  color: black;
`;

export function MultichainConnectButton(): JSX.Element | null {
  const { connected } = useWallet();
  const { openConnectModal } = useModal();

  return (
    <>
      {!connected && (
        <StyledButton type="button" onClick={openConnectModal}>
          Connect
        </StyledButton>
      )}
      <MultichainConnectedButton />
    </>
  );
}