githubEdit

Context

MoonSDKProvider Documentation

The MoonSDKProvider is a React context provider that provides access to the Moon SDK and other related functionality to its child components. This documentation page will guide you through the basics of using the MoonSDKProvider in your React project.

Table of Contents

  • Installation

  • Usage

  • Context Values

  • Example

Installation

To use the MoonSDKProvider in your project, you'll need to install the @moonup/moon-react package. You can install it using npm:

npm install @moonup/moon-react

Usage

To use the MoonSDKProvider, you'll need to wrap your application with it. Here's an example of how to do this:

import React from 'react';
import { MoonSDKProvider } from '@moonup/moon-react';
import App from './App';

export default function Main() {
  return (
    <MoonSDKProvider>
      <App />
    </MoonSDKProvider>
  );
}

MoonSDKProvider context:

connect(accessToken?: string, refreshToken?: string)

Connects to the Moon API using the provided access and refresh tokens.

Example:

disconnect()

Disconnects from the Moon API.

Example:

getUserSession()

Retrieves the current user session.

Example:

connectEthers()

Connects to the Moon Ethers provider.

Example:

disconnectEthers()

Disconnects from the Moon Ethers provider.

Example:

request(args: any)

Sends a request to the Moon Ethers provider.

Example:

signOut()

Signs out the current user.

Example:

createWallet()

Creates a new Ethereum wallet and adds it to the Moon SDK.

Example:

listWallets()

Retrieves the list of Ethereum wallets managed by the Moon SDK.

Example:

setWallet(wallet: string)

Sets the currently selected Ethereum wallet address.

Example:

getChains()

Retrieves the list of supported blockchain networks.

Example:

Example

Here's an example of how to use the MoonSDKProvider to retrieve the list of Ethereum wallets managed by the Moon SDK:

In this example, we import the useMoonSDK hook from the @moonup/moon-react package and use it to access the wallets and listWallets context values. We then use these values to retrieve the list of Ethereum wallets managed by the Moon SDK and display them in a list

Last updated