0.1.0 • Published 3 years ago

@dssd1001/wallet-adapter v0.1.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

@dssd1001/wallet-adapter

Modular TypeScript wallet adapters and components for Solana applications.

Wallets

Quick Links

Quick Setup (using React UI)

There are also material-ui and ant-design packages if you use those component frameworks.

Install

Install these dependencies:

yarn add @dssd1001/wallet-adapter-wallets \
         @dssd1001/wallet-adapter-base \
         @dssd1001/wallet-adapter-react \
         @dssd1001/wallet-adapter-react-ui \
         @solana/web3.js \
         react

Setup

import React, { FC, useMemo } from 'react';
import { ConnectionProvider, WalletProvider } from '@dssd1001/wallet-adapter-react';
import { WalletAdapterNetwork } from '@dssd1001/wallet-adapter-base';
import {
    getLedgerWallet,
    getPhantomWallet,
    getSlopeWallet,
    getSolflareWallet,
    getSolletExtensionWallet,
    getSolletWallet,
    getTorusWallet,
} from '@dssd1001/wallet-adapter-wallets';
import {
    WalletModalProvider,
    WalletDisconnectButton,
    WalletMultiButton
} from '@dssd1001/wallet-adapter-react-ui';
import { clusterApiUrl } from '@solana/web3.js';

// Default styles that can be overridden by your app
require('@dssd1001/wallet-adapter-react-ui/styles.css');

export const Wallet: FC = () => {
    // Can be set to 'devnet', 'testnet', or 'mainnet-beta'
    const network = WalletAdapterNetwork.Devnet;

    // You can also provide a custom RPC endpoint
    const endpoint = useMemo(() => clusterApiUrl(network), [network]);

    // @dssd1001/wallet-adapter-wallets includes all the adapters but supports tree shaking --
    // Only the wallets you configure here will be compiled into your application
    const wallets = useMemo(() => [
        getPhantomWallet(),
        getSlopeWallet(),
        getSolflareWallet(),
        getTorusWallet({
            options: { clientId: 'Get a client ID @ https://developer.tor.us' }
        }),
        getLedgerWallet(),
        getSolletWallet({ network }),
        getSolletExtensionWallet({ network }),
    ], [network]);

    return (
        <ConnectionProvider endpoint={endpoint}>
            <WalletProvider wallets={wallets} autoConnect>
                <WalletModalProvider>
                    <WalletMultiButton />
                    <WalletDisconnectButton />
                </WalletModalProvider>
            </WalletProvider>
        </ConnectionProvider>
    );
};

You can pass in these optional display props to WalletModalProvider:

proptypedefaultdescription
classNamestring""additional modal class name
logoReactNodeundefinedyour logo url or image element
featuredWalletsnumber3initial number of wallets to display in the modal
containerstring"body"CSS selector for the container element to append the modal to

For example, to show your logo:

<WalletModalProvider logo="YOUR_LOGO_URL">...</WalletModalProvider>

logo example

Modal logo example

Usage

import { WalletNotConnectedError } from '@dssd1001/wallet-adapter-base';
import { useConnection, useWallet } from '@dssd1001/wallet-adapter-react';
import { Keypair, SystemProgram, Transaction } from '@solana/web3.js';
import React, { FC, useCallback } from 'react';

export const SendOneLamportToRandomAddress: FC = () => {
    const { connection } = useConnection();
    const { publicKey, sendTransaction } = useWallet();

    const onClick = useCallback(async () => {
        if (!publicKey) throw new WalletNotConnectedError();

        const transaction = new Transaction().add(
            SystemProgram.transfer({
                fromPubkey: publicKey,
                toPubkey: Keypair.generate().publicKey,
                lamports: 1,
            })
        );

        const signature = await sendTransaction(transaction, connection);

        await connection.confirmTransaction(signature, 'processed');
    }, [publicKey, sendTransaction, connection]);

    return (
        <button onClick={onClick} disabled={!publicKey}>
            Send 1 lamport to a random address!
        </button>
    );
};

Packages

This library is organized into small packages with few dependencies. To add it to your dApp, you only need the core packages and UI components for your chosen framework.

Core

These packages are what most projects can use to support wallets on Solana.

packagedescriptionnpm
walletsAll wallets with icons@dssd1001/wallet-adapter-wallets
baseAdapter interfaces, error types, and common utilities@dssd1001/wallet-adapter-base
reactContexts and hooks for React dApps@dssd1001/wallet-adapter-react
angular *Stores and configuration for Angular dApps@dssd1001/wallet-adapter-angular
vueStores and composables for Vue 3 dApps@dssd1001/wallet-adapter-vue
svelte *Stores for Svelte dApps@dssd1001/wallet-adapter-svelte

* Package has not been published to NPM yet.

UI Components

These packages provide components for common UI frameworks.

packagedescriptionnpm
material-uiComponents for Material UI@dssd1001/wallet-adapter-material-ui
ant-designComponents for Ant Design@dssd1001/wallet-adapter-ant-design
react-uiComponents for React (no UI framework, just CSS)@dssd1001/wallet-adapter-react-ui
vue-uiComponents for Vue (no UI framework, just CSS)@dssd1001/wallet-adapter-vue-ui

Starter Projects

These packages provide projects that you can use to start building a dApp with built-in wallet support. Alternatively, check out dapp-scaffold for a more complete framework.

packagedescriptionnpm
exampleDemo of UI components@dssd1001/wallet-adapter-example
material-ui-starterCreate React App project using Material UI@dssd1001/wallet-adapter-material-ui-starter
react-ui-starterCreate React App project using React UI@dssd1001/wallet-adapter-react-ui-starter
nextjs-starterNext.js project using React@dssd1001/wallet-adapter-nextjs-starter

Wallets

These packages provide adapters for each wallet. The core wallets package already includes them, so you don't need to add these as dependencies.

packagedescriptionnpm
bitkeepAdapter for BitKeep@dssd1001/wallet-adapter-bitkeep
bitpieAdapter for Bitpie@dssd1001/wallet-adapter-bitpie
bloctoAdapter for Blocto@dssd1001/wallet-adapter-blocto
cloverAdapter for Clover@dssd1001/wallet-adapter-clover
coin98Adapter for Coin98@dssd1001/wallet-adapter-coin98
coinhubAdapter for Coinhub@dssd1001/wallet-adapter-coinhub
ledgerAdapter for Ledger@dssd1001/wallet-adapter-ledger
mathwalletAdapter for MathWallet@dssd1001/wallet-adapter-mathwallet
phantomAdapter for Phantom@dssd1001/wallet-adapter-phantom
safepalAdapter for SafePal@dssd1001/wallet-adapter-safepal
slopeAdapter for Slope@dssd1001/wallet-adapter-slope
solflareAdapter for Solflare@dssd1001/wallet-adapter-solflare
solletAdapter for Sollet@dssd1001/wallet-adapter-sollet
solongAdapter for Solong@dssd1001/wallet-adapter-solong
tokenpocketAdapter for TokenPocket@dssd1001/wallet-adapter-tokenpocket
torusAdapter for Torus@dssd1001/wallet-adapter-torus
walletconnect *Adapter for WalletConnect@dssd1001/wallet-adapter-walletconnect

* Package has not been published to NPM yet.

Build from Source

  1. Clone the project:
git clone https://github.com/solana-labs/wallet-adapter.git
  1. Install dependencies:
cd wallet-adapter
yarn install
  1. Build all packages:
yarn build
  1. Run locally:
cd packages/starter/react-ui-starter
yarn start
0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago