Unlink Accessories

ARTM

Asset Registry Transaction Message (ARTM) describes the standard approach for parsing updates to the off-chain Asset Register database. One ARTM can describe multiple sequential operations on the Asset Register.

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

{
  type: 'asset-link',
  action: 'delete',
  args: [
    
    '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',
  ],
}

The user must own both assets to delete links unless it is an off-chain asset, where only the creator of the child asset can delete a link. Unlinking between assets owned on a FuturePass account and the FuturePass account owner's EOA is allowed. As long as the ownership resolution is satisfied, links can also be deleted across chains.

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

const unlinkOperation = {
  type: 'asset-link',
  action: 'delete',
  args: [
    'equipWith_asmBrain',
    'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
    '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(unlinkOperation)
    return submitAsync({ artm })
  }

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

Last updated

Feedback

Docs

© 2023 -> ♾️