0.5.0 • Published 2 years ago

@tomlisankie/wallet-adapter v0.5.0

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

@tomlisankie/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 @tomlisankie/wallet-adapter-base \
         @tomlisankie/wallet-adapter-react \
         @tomlisankie/wallet-adapter-react-ui \
         @tomlisankie/wallet-adapter-wallets \
         @solana/web3.js \
         react

Setup

import React, { FC, useMemo } from 'react';
import { ConnectionProvider, WalletProvider } from '@tomlisankie/wallet-adapter-react';
import { WalletAdapterNetwork } from '@tomlisankie/wallet-adapter-base';
import {
    GlowWalletAdapter,
    LedgerWalletAdapter,
    PhantomWalletAdapter,
    SlopeWalletAdapter,
    SolflareWalletAdapter,
    SolletExtensionWalletAdapter,
    SolletWalletAdapter,
    TorusWalletAdapter,
} from '@tomlisankie/wallet-adapter-wallets';
import {
    WalletModalProvider,
    WalletDisconnectButton,
    WalletMultiButton
} from '@tomlisankie/wallet-adapter-react-ui';
import { clusterApiUrl } from '@solana/web3.js';

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

export const Wallet: FC = () => {
    // The network 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]);

    // @tomlisankie/wallet-adapter-wallets includes all the adapters but supports tree shaking and lazy loading --
    // Only the wallets you configure here will be compiled into your application, and only the dependencies
    // of wallets that your users connect to will be loaded.
    const wallets = useMemo(
        () => [
            new PhantomWalletAdapter(),
            new GlowWalletAdapter(),
            new SlopeWalletAdapter(),
            new SolflareWalletAdapter({ network }),
            new TorusWalletAdapter(),
        ],
        [network]
    );

    return (
        <ConnectionProvider endpoint={endpoint}>
            <WalletProvider wallets={wallets} autoConnect>
                <WalletModalProvider>
                    <WalletMultiButton />
                    <WalletDisconnectButton />
                    { /* Your app's components go here, nested within the context providers. */ }
                </WalletModalProvider>
            </WalletProvider>
        </ConnectionProvider>
    );
};

Usage

import { WalletNotConnectedError } from '@tomlisankie/wallet-adapter-base';
import { useConnection, useWallet } from '@tomlisankie/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'll need core packages, some wallets, and UI components for your chosen framework.

Core

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

packagedescriptionnpm
baseAdapter interfaces, error types, and common utilities@tomlisankie/wallet-adapter-base
reactContexts and hooks for React dApps@tomlisankie/wallet-adapter-react

Wallets

These packages provide adapters for each wallet. You can use the wallets package, or add the individual wallet packages you want.

packagedescriptionnpm
walletsIncludes all the wallets (with tree shaking)@tomlisankie/wallet-adapter-wallets
bitkeepAdapter for BitKeep@tomlisankie/wallet-adapter-bitkeep
bitpieAdapter for Bitpie@tomlisankie/wallet-adapter-bitpie
bloctoAdapter for Blocto@tomlisankie/wallet-adapter-blocto
cloverAdapter for Clover@tomlisankie/wallet-adapter-clover
coin98Adapter for Coin98@tomlisankie/wallet-adapter-coin98
coinhubAdapter for Coinhub@tomlisankie/wallet-adapter-coinhub
glowAdapter for Glow@tomlisankie/wallet-adapter-glow
huobiAdapter for HuobiWallet@tomlisankie/wallet-adapter-huobi
glowAdapter for Glow@tomlisankie/wallet-adapter-glow
ledgerAdapter for Ledger@tomlisankie/wallet-adapter-ledger
mathwalletAdapter for MathWallet@tomlisankie/wallet-adapter-mathwallet
phantomAdapter for Phantom@tomlisankie/wallet-adapter-phantom
safepalAdapter for SafePal@tomlisankie/wallet-adapter-safepal
slopeAdapter for Slope@tomlisankie/wallet-adapter-slope
solflareAdapter for Solflare@tomlisankie/wallet-adapter-solflare
solletAdapter for Sollet@tomlisankie/wallet-adapter-sollet
solongAdapter for Solong@tomlisankie/wallet-adapter-solong
tokenpocketAdapter for TokenPocket@tomlisankie/wallet-adapter-tokenpocket
torusAdapter for Torus@tomlisankie/wallet-adapter-torus

UI Components

These packages provide components for common UI frameworks.

packagedescriptionnpm
react-uiComponents for React (no UI framework, just CSS)@tomlisankie/wallet-adapter-react-ui
material-uiComponents for Material UI with React@tomlisankie/wallet-adapter-material-ui
ant-designComponents for Ant Design with React@tomlisankie/wallet-adapter-ant-design
angular-material-uiComponents for Angular Material UI@heavy-duty/wallet-adapter-material

Starter Projects

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

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

Community

Several packages are maintained by the community to support additional frontend frameworks.

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.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago