0.1.18 • Published 1 day ago

@opensea/wallet v0.1.18

Weekly downloads
-
License
-
Repository
-
Last release
1 day ago

OpenSea Wallet React SDK

Get Started

Installation

Install the package.

npm install @opensea/wallet

Setup

Mount the WalletProvider component. This will give any descendant or child components access to the authentication state and methods through the useAuth hook.

// App.tsx
import { WalletProvider } from "@opensea/wallet"
import { AppContents } from "./AppContents"

function App() {
  return (
    <WalletProvider>
      <AppContents />
    </WalletProvider>
  )
}

Next apply the CSS used by the OpenSea login dialog. If you are using a framework that supports importing CSS files you can import with:

import "@opensea/wallet/style.css"

Usage

Use the useAuth hook to access the current authentication state and the login/logout methods.

// AppContents.tsx
import { useAuth } from "@opensea/wallet"
import { LoadingState } from "./LoadingState"

export function AppContents() {
  const { ready, user, login, logout } = useAuth()

  if (!ready) {
    return <LoadingState />
  }

  if (!user) {
    return <button onClick={login}>Login</button>
  }

  return (
    <>
      <p>Address: {user.addresses[0]}</p>
      <p>Email: {user.email}</p>
      <p>Privy ID: {user.privyId}</p>
      <p>Access Token: {user.accessToken}</p>
      <button onClick={logout}>Login</button>
    </>
  )
}

Documentation

WalletProvider

type WalletProviderConfig = {
  environment: "production" | "development"
}

type WalletProviderProps {
  config: WalletProviderConfig
}

function WalletProvider({ environment = "development" }: WalletProviderProps): JSX.Element

useAuth

type User = {
  addresses: readonly Address[]
  email?: string
  privyId?: string
  accessToken?: string
}

type AuthContextType = {
  // Properties
  /**
   * Returns true once authentication status has been confirmed after initial page load.
   *
   * Wait until `ready` is true before using the `user` property.
   */
  ready: boolean
  /**
   * The current user, or undefined if not logged in.
   *
   * Wait until `ready` is true before using this property.
   */
  user: User | undefined

  // Methods
  /**
   * Opens a login dialog.
   */
  login: () => void
  /**
   * Logs the user out.
   * @returns A promise that resolves once the user is logged out.
   */
  logout: () => Promise<void>
}

function useAuth(): AuthContextType
0.1.16

2 days ago

0.1.17

2 days ago

0.1.18

1 day ago

0.1.17-rc.0

2 days ago

0.1.15

2 days ago

0.1.10

6 days ago

0.1.11

6 days ago

0.1.12

6 days ago

0.1.13

6 days ago

0.1.14

5 days ago

0.1.8

9 days ago

0.1.9

9 days ago

0.1.7

12 days ago

0.1.6

12 days ago

0.1.2

13 days ago

0.1.4

13 days ago

0.1.3

13 days ago

0.1.5

13 days ago

0.1.0

15 days ago

0.1.1

15 days ago

0.0.1-rc.17

24 days ago

0.0.1-rc.15

25 days ago

0.0.1-rc.16

25 days ago

0.0.1-rc.13

1 month ago

0.0.1-rc.14

30 days ago

0.0.1-rc.12

1 month ago

0.0.1-rc.11

1 month ago

0.0.1-rc.10

1 month ago

0.0.1-rc.9

2 months ago

0.0.1-rc.8

2 months ago

0.0.1-rc.7

2 months ago

0.0.1-rc.3

3 months ago

0.0.1-rc.4

3 months ago

0.0.1-rc.2

3 months ago

0.0.1-rc.5

3 months ago

0.0.1-rc.6

3 months ago

0.0.1-rc.1

3 months ago