Access Futureverse constants

The Futureverse-specific constants are available as:

const { CONSTANTS } = useFutureverse()

These constants will match the stage you defined when configuring FutureverseProvider (either development or production).

There are four categories of constants:

  • CONTRACTS - all relevant Futureverse contract addresses

  • CHAINS - Ethereum Mainnet, Ethereum Goerli Testnet, The Root Network Mainnet and The Root Network Porcini Testnet

  • ENDPOINTS - all relevant Futureverse endpoints (e.g. the Asset Indexer)

  • MISC - miscellaneous.

For example, you could use the CHAINS constant to get the chain ID of The Root Network and fetch the balance of XRP using Wagmi, like so:

import { useFutureverse } from '@futureverse/react'
import { useAccount, useBalance } from 'wagmi'

function Home() {
	const { CONSTANTS } = useFutureverse()

  const xrpBalanceOnTrn = useBalance({
    address: account.address,
    chainId: CONSTANTS.CHAINS.TRN.id,
  })

  return (
    <div>
      <p>
        User Balance: {xrpBalanceOnTrn.data?.formatted ?? 'loading'} ETH
      </p>
    </div>
  )
}

export default Home

Wagmi Signer caveat

The wagmi useSinger returns null after refreshing the page. To access the provider and signer, use the following hook:

export function useConfigSigner() {
  const { data: signer } = useSigner()
  const provider = useProvider()
  const { isDisconnected } = useAccount()
  const { userSession, loginModal } = useFutureverse()
  const { disconnect } = useDisconnect()

  /**
   * This helps avoid the situation where the wagmi wallet can be connected, but
   * FuturePass is not.
   */
  useEffect(() => {
    if (!isDisconnected && !loginModal && !userSession) disconnect()
  }, [isDisconnected, userSession, loginModal, disconnect])

  useEffect(() => {
    // provider and signer are available here
  }, [provider, signer])
}

Last updated

Feedback

Docs

© 2023 -> ♾️