@futureverse/asset-register-react
TypeScript icon, indicating that this package has built-in type declarations

2.70.2 • Public • Published

Futureverse Asset Register SDK

Installation

NPM:

    npm install @futureverse/asset-register-react --save

Yarn:

    yarn add @futureverse/asset-register-react

Usage

import { useCreateSchema } from '@futureverse/asset-register-react'
import { NamespaceUrl } from '@futureverse/asset-register/types'
import { useState, useMemo } from 'react'
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts'

const ASSET_REGISTER_ENDPOINT =
  'https://saybx2ywpd.execute-api.us-west-2.amazonaws.com/graphql'
const APP_DOMAIN = 'com.fv.app'
const WALLET_PRIVATE_KEY = ''
const APP_ORIGIN = 'http://com.fv.app/login'

const wallet = privateKeyToAccount(generatePrivateKey())
const walletAddress = wallet.address

function App() {
  const auth = useMemo(
    () => ({
      domain: APP_DOMAIN,
      origin: APP_ORIGIN,
      chainId: 1,
      sign: async (message) => {
        return await wallet.signMessage({ message })
      },
      walletAddress,
    }),
    [],
  )
  return (
    // Provide the client to your App
    <AssetRegisterClientProvider url={ASSET_REGISTER_ENDPOINT} auth={auth}>
      <SchemaCreator />
    </AssetRegisterClientProvider>
  )
}

export const SchemaCreator = () => {
  const [version, setVersion] = useState(1)
  const [schema, setSchema] = useState('{}')
  const [name, setName] = useState('schemaName')
  const [namespace, setNamespace] = useState<NamespaceUrl>(
    'http://schema.futureverse.dev/fv' as NamespaceUrl,
  )
  const { createAsync: createSchemaAsync, schema: createdSchema } =
    useCreateSchema()

  const handleCreateMutate = async () => {
    try {
      await createSchemaAsync({
        schema,
        version,
        namespace,
        name,
      })
      setVersion(version + 1)
    } catch (e) {
      alert(e)
    }
  }

  return (
    <div>
      <div>
        <label>version: </label>
        <input
          value={version}
          type="number"
          onChange={(e) => setVersion(parseInt(e.target.value))}
        />
      </div>
      <div>
        <label>namespace: </label>
        <input
          value={namespace}
          size={80}
          onChange={(e) => setNamespace(e.target.value as NamespaceUrl)}
        />
      </div>
      <div>
        <label>name: </label>
        <input
          value={name}
          size={80}
          onChange={(e) => setName(e.target.value as NamespaceUrl)}
        />
      </div>
      <div>
        <label>schema: </label>
        <textarea
          rows={10}
          cols={80}
          value={schema}
          onChange={(e) => setSchema(e.target.value)}
        />
      </div>
      <br />
      <button onClick={handleCreateMutate}>create schema</button>

      {createdSchema && <div>{`Schema Name: ${createdSchema.name}`}</div>}
    </div>
  )
}

render(<App />, document.getElementById('root'))

Troubleshoots

  1. ERR_UNSUPPORTED_DIR_IMPORT error on the nextjs project

    In case you encounter the ERR_UNSUPPORTED_DIR_IMPORT error while utilizing this SDK in your Next.js project, simply include the following configuration to the next.config.js file. For more details, please refer to here

//...
experimental: {
  esmExternals: false,
},
//...

Migration guide from @futureverse/asset-registry-react package

The new package name for this library is now @futureverse/asset-register-react. Hence, there are some files and codes that have been renamed in the new version. Here are the migration guides:

  • The package dependency @futureverse/asset-registry has been changed to refer to @futureverse/asset-register
  • Renamed files:
    • ./src/hooks/AssetRegistryClientProvider.tsx file is now ./src/hooks/AssetRegisterClientProvider.tsx
    • ./src/hooks/useAssetRegistryClientContext.ts file is now ./src/hooks/useAssetRegisterClientContext.ts
  • AssetRegistryClientProvider provider class is now AssetRegisterClientProvider
  • useAssetRegistryClientContext React hook is now useAssetRegisterClientContext

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.54.60rc
2.48.0-rc.30dev
2.70.229latest
2.54.0-beta.26beta

Version History

VersionDownloads (Last 7 Days)Published
2.70.229
2.54.0-beta.26
2.70.124
2.70.011
2.69.10
2.69.03
2.68.19
2.68.07
2.67.00
2.66.05
2.65.00
2.64.111
2.64.00
2.63.20
2.63.10
2.63.01
2.62.00
2.61.10
2.61.00
2.60.20
2.60.10
2.60.00
2.54.0-beta.10
2.59.11
2.59.00
2.58.00
2.57.20
2.57.10
2.57.00
2.56.00
2.55.00
2.54.70
2.54.0-beta.01
2.53.0-beta.00
2.52.0-beta.00
2.54.60
2.54.51
2.54.40
2.54.30
2.54.20
2.54.10
2.54.00
2.53.20
2.53.10
2.53.00
2.52.00
2.51.50
2.51.40
2.51.30
2.51.20
2.51.2-beta.00
2.51.17
2.51.00
2.48.0-rc.30
2.48.0-rc.20
2.48.0-rc.10
2.47.00
2.47.0-rc.40
2.47.0-rc.31
2.47.0-rc.20
2.47.0-rc.10
2.46.1-rc.10
2.46.00
2.46.0-rc.30
2.46.0-rc.20
2.46.0-rc.10
2.45.10
2.45.1-rc.10
2.45.00
2.45.0-rc.50
2.45.0-rc.40
2.45.0-rc.30
2.45.0-rc.20
2.45.0-rc.10
2.44.1-rc.20
2.44.1-rc.10
2.44.00
2.44.0-rc.10
2.43.1-rc.10
2.43.00
2.42.00
2.41.00
2.40.00
2.39.10
2.39.00
2.38.00
2.37.11
2.37.00
2.36.01
2.35.00
2.34.00
2.33.00
2.32.00
2.31.01
2.30.00
2.29.00
2.28.00
2.27.00
2.26.00
2.25.00
2.24.00
2.23.00
2.22.10
2.22.00
2.21.00
2.20.00
2.19.00
2.18.00
2.17.00
2.16.20
2.16.10
2.16.00
2.15.00
2.14.00
2.13.10
2.13.00
2.12.00
2.11.00

Package Sidebar

Install

npm i @futureverse/asset-register-react

Weekly Downloads

120

Version

2.70.2

License

none

Unpacked Size

2.35 MB

Total Files

85

Last publish

Collaborators

  • developer-darpan
  • admin-futureverse
  • tknff
  • garethdainesnpm
  • jcsanpedro
  • nick95550
  • fv-shaun
  • felixschl
  • fv-philip.roigard
  • chris_futureverse
  • aidan-starke