npm

@aptstats/aptos-wallet-framework
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

aptos-wallet-framework

React WalletProvider supporting loads of aptos wallets.

This repo is initially forked from Hippo space, the reason for doing this is that original implementation supports a lot of wallets and put all the dependencies into one and I couldn't stand it.

This Repo takes almost the same code from the original one, but split all the extensions into different packages, by doing this, developers can choose to install packages freely without having to worry about extra wasted node modules.

Extension list

Advertisement.

Installation

with yarn

yarn add @aptstats/aptos-wallet-framework

with npm

npm install @aptstats/aptos-wallet-framework

Examples

Wallet integration

Use React Provider

import React from 'react';
import { WalletProvider } from '@aptstats/aptos-wallet-framework';
import { PetraWalletAdapter } from '@aptstats/petra-wallet-extension';
import { SpacecyWalletAdapter } from '@aptstats/spacecy-wallet-extension';
import { OKXWalletAdapter } from '@aptstats/okx-wallet-extension';

const wallets = [new PetraWalletAdapter(), new SpacecyWalletAdapter(), new OKXWalletAdapter()];

const App: React.FC = () => {
  return (
    <WalletProvider
      wallets={wallets}
      autoConnect={true | false} /** allow auto wallet connection or not **/
      onError={(error: Error) => {
        console.log('Handle Error Message', error);
      }}
    >
      {/* your website */}
    </WalletProvider>
  );
};

export default App;

Web3 Hook

import { useWallet } from 'aptstats/aptos-wallet-adapter';

const { connected, account, network, ...rest } = useWallet();

Connect & Disconnect

import { AptosWalletName, useWallet } from "@aptstats/aptos-wallet-adapter"

...

const { connect, disconnect, connected } = useWallet();

/* No more manual connection required if you disable auto-connect mode while the previous select + connect will still work */

if (!connected) {
  return (
    <button
      onClick={() => {
        connect(walletName); // E.g. connecting to the Aptos official wallet
      }}
    >
      Connect
    </button>
  );
} else {
  return (
    <button
      onClick={() => {
        disconnect();
      }}
    >
      Disconnect
    </button>
  );
}

Package Sidebar

Install

npm i @aptstats/aptos-wallet-framework

Weekly Downloads

38

Version

0.0.6

License

none

Unpacked Size

98 kB

Total Files

58

Last publish

Collaborators

  • eric.allen