Management API Reference

Hooks

React hooks provided by Openfort Kit for seamless integration with Openfort SDK.

Openfort Kit provides a set of hooks to interact with the Openfort SDK. These hooks are designed to make it easier to integrate Openfort into your React application.

useStatus#

The useStatus hook provides the current status of the Openfort SDK. The status can be one of the following:

  • LOADING: The SDK is loading
  • CONNECTED: The user is connected
  • DISCONNECTED: The user is disconnected
  • NEEDS_RECOVERY: The SDK needs the recovery phrase to be entered.
  • DISCONNECTED_WITH_ADDRESS: The SDK is disconnected with an address. This can happen when the user has connected to a Web3 wallet without connecting to Openfort.

It also provides helpful boolean values to check the status, like isConnected or isLoading.


_10
import { useStatus } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const { status, isConnected, isLoading } = useStatus()
_10
}

useUser#

Hook to get the current user. It returns the following properties:

  • user: The user object.
  • getAccessToken: A function to get the access token.

_10
import { useUser } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const { user, getAccessToken } = useUser()
_10
}

The user object contains combines the user's information with the Openfort player id:


_13
{
_13
"id": "pla_ff54b031-a878-4ca2-9cf5-ae190f921e9b",
_13
"object": "player",
_13
"createdAt": 1691658234,
_13
"linkedAccounts": [
_13
{
_13
"provider": "email",
_13
"email": "jaume@openfort.xyz",
_13
"disabled": false,
_13
"updatedAt": 1691658234
_13
}
_13
]
_13
}

To get the address of the user, you would use wagmi's useAccount hook:


_10
import { useAccount } from 'wagmi';
_10
_10
function App() {
_10
const { address } = useAccount();
_10
}

useProviders#

Hook to get the providers. It returns the following properties:

  • linkedProviders: An array of providers that the user has linked. If user is not connected, the array will be empty.
  • allProviders: An array of all providers.
  • availableProviders: An array of providers that the user can link. (All providers except the ones that are already linked)

_10
import { useProviders } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const { linkedProviders, availableProviders, allProviders } = useProviders();
_10
}

useWallets#

Hook to get the wallets liked by the user and available on the current device. It returns the following properties:

  • wallets: An array of wallets linked by the user.
  • currentWallet: The current active wallet.
  • setActiveWallet: A function to set the active wallet.

_10
import { useIsMounted } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const { wallets, setActiveWallet, currentWallet } = useWallets()
_10
}

useLogout#

Hook to logout the user. It returns a function that you can call to logout the user.


_10
import { useLogout } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const logout = useLogout();
_10
}

useModal#

Hook for controlling the modal. It returns the following functions:

  • setOpen: Sets the modal open state.
  • openWallets: Opens the wallets page.
  • openProviders: Opens the providers page. (Only available if the user is connected)
  • openSwitchNetworks: Opens the switch networks page. (Only available if the user is connected)

_10
import { useModal } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const { openSwitchNetworks, setOpen, openProviders, openWallets } = useModal();
_10
}

useChains#

Hook to get the chains set in the wagmi configuration. It returns an array of chains.


_10
import { useChains } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const chains = useChains();
_10
}

useChainIsSupported#

Hook to check if a chain is supported. It returns a function that you can call to check if a chain is supported.


_10
import { useChains, useChainIsSupported } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const chains = useChains();
_10
const chainIsSupported = useChainIsSupported(chains?.[0]?.id);
_10
}

useIsMounted#

Helper hook to check if the component is mounted. It returns a boolean value. Useful for ssr apps.


_10
import { useIsMounted } from "@openfort/openfort-kit";
_10
_10
function App() {
_10
const isMounted = useIsMounted();
_10
}