Owner Link

Overview

If you own both the parent and child collections and want to link assets between them, you can use the owner-link operation type as shown below.

An asset link creation operation within an ARTM typically consists of the following structure:

{
  type: 'owner-link',
  action: 'create',
  args: [
    // Operator
    'equipWith_asmBrain',
    // Opearand A: Boxer Asset ID
    'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
    // Opearand B: Brain Asset ID
    'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
  ],
}

To create links, the sender of the transaction must be the owner of both assets' collections. Linking between assets owned on a Pass account and the Pass account owner's EOA is allowed. Links can also be created across chains as long as the ownership resolution is satisfied.

Usage

import {
  useGetARTM,
  useSignAndSubmitTransaction,
  useGetTransaction,
} from '@futureverse/asset-register-react/v2'

const linkOperation = {
  type: 'owner-link',
  action: 'create',
  args: [
    'equipWith_asmBrain',
    // Boxer
    'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
    // Brain
    'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
  ],
}

const LinkAccessory = ({ address }) => {
  const {
    artm,
    reactQuery: { refetch: getARTM },
  } = useGetARTM(
    {
      address,
      [],
    },
    { enabled: false },
  )

  const { submitAsync, transaction } = useSignAndSubmitTransaction()
  // Polling tx status after submitted
  const { transaction: transactionStatus } = useGetTransaction(
    { transactionHash: transaction?.transactionHash as any },
    {
      refetchInterval: (data) => (data?.status === 'PENDING' ? 2000 : false),
      enabled: !!transaction?.transactionHash,
    },
  )

  const submitARTM = async () => {
    const { data: artm } = await getARTM()
    if (!artm) {
      return
    }
    artm.addOperation(linkOperation)
    return submitAsync({ artm })
  }

  return (
    <>
      <button onClick={submitARTM}>Submit link accessory TX</button>
      {transactionStatus && <div>{`tx status: ${transactionStatus.status}`}</div>}
    </>
  )
}
import {
  useGetARTM,
  useSignAndSubmitTransaction,
  useGetTransaction,
} from '@futureverse/asset-register-react/v2'

const linkOperation = {
  type: 'owner-link',
  action: 'delete',
  args: [
    'equipWith_asmBrain',
    // Boxer
    'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
    // Brain
    'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
  ],
}

const LinkAccessory = ({ address }) => {
  const {
    artm,
    reactQuery: { refetch: getARTM },
  } = useGetARTM(
    {
      address,
      [],
    },
    { enabled: false },
  )

  const { submitAsync, transaction } = useSignAndSubmitTransaction()
  // Polling tx status after submitted
  const { transaction: transactionStatus } = useGetTransaction(
    { transactionHash: transaction?.transactionHash as any },
    {
      refetchInterval: (data) => (data?.status === 'PENDING' ? 2000 : false),
      enabled: !!transaction?.transactionHash,
    },
  )

  const submitARTM = async () => {
    const { data: artm } = await getARTM()
    if (!artm) {
      return
    }
    artm.addOperation(linkOperation)
    return submitAsync({ artm })
  }

  return (
    <>
      <button onClick={submitARTM}>Submit link accessory TX</button>
      {transactionStatus && <div>{`tx status: ${transactionStatus.status}`}</div>}
    </>
  )
}

Last updated

© 2023 -> ♾️