Asset Register Transaction

Transactions are made to the Asset Register using a messaging standard designed to be human readable and familiar to blockchain users using the Ethereum message standard.

Asset Register Transaction Message

To make changes to the asset register you must make transactions using signed Ethereum messages. An Asset Register Transaction Message (ARTM) can be generated using the ARTM SDK and looks like this:

Asset Registry transaction

An update is being made to your inventory

Operations:

asset-link delete
- equipWith_asmBrain
- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000
- did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:20
end

asset-link create
- equipWith_asmBrain
- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000
- did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21
end

asset-link create
- http://schema.futureverse.com/tnl#equipWith_gloves
- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000
- did:fv-asset:1:root:0x1ea66a857de297471bc12dd12d93853ff6617284:21
end

delegate delete
- 0x6bca6de2dbdc4e0d41f7273011785ea16ba47182 (FPPass address - account 1)
- 0x6bca6de2dbdc4e0d41f7273011785ea16ba47183 (FPPass address - account 2)
end

ownership update
- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000
- 0x6bca6de2dbdc4e0d41f7273011785ea16ba47182
end

asset-link create
- equipwith_hairStyle
- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000
- did:fv-asset:off-chain:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1234
end

Operations END

Address: 0x854A3E045Ac44a7f4A1726AdAC576029135DFdA7
Nonce:1

ARTM Creation

React - useGetARTM

import { useGetARTM } from '@futureverse/asset-registry-react'

const Page = () => {
  const { data: artm } = useGetARTM({
    address: signer.address,
    operations,
  })
  
  // use artm elsewhere in the component
}

The artm object is defined in ARTM SDK. Therefore, signing can be done manually and then sent to the Asset Register API using the Asset Mutation, or it can be used with the useAssetMutation hook directly.

Library - ARTM SDK

Under the hood, the React library uses the ARTM SDK. This library is specifically built to enable the creation, signing, and validation of ARTMs. Creating an ARTM message is described in detail on the NPM page.

Nonce

Like a traditional blockchain, the Asset Register uses nonces to prevent replay attacks. The nonce for a chain address can be queried using the Asset Register API as follows:

query GetNonce($input: NonceInput!) {
  getNonceForChainAddress(input: $input)
}
{
  "input": {
    "chainAddress": "0xc07Bdbf297Caa9488D194835298eE7037C861143"
  }
}

Submitting Transactions

React - useSubmitTransaction

import { useAssetMutationMutation, useGetARTM } from '@futureverse/asset-registry-react'

const Page = () => {
  const { data: artm } = useGetARTM({
    address: signer.address,
    operations,
  })
  
  const { mutateAsync: submitTransactionAsync, data } = useSubmitTransaction()
  
  const submitARTM = async () => {
    // Sign transaction and set on the ARTM instance to validate signature
    const signature = await signer.signMessage(artm.getMessageToSign())
    artm.setSignature(signature)
    
    // Submit transaction to Asset Registry API
    submitTransactionAsync({
      input: {
          transaction: artm.message,
          signature: artm.signature
      }
    })
  }
  
  return (
    <button onClick={() => submitARTM()}>Submit ARTM</button>
  )
}

GraphQL - Submit Transaction

mutation SubmitTransaction($input: SubmitTransactionInput!) {
  submitTransaction(input: $input) {
    transactionHash
  }
}
{
  "input": {
    "transaction":"Asset Registry transaction\n\nAn update is being made to your inventory\n\nOperations:\n\nasset-link create\n- equipWith_asmBrain\n- did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000\n- did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21\nend\n\nOperations END\n\nAddress: 0x225b5333C2D8EC41F40D6463D44141786C2c4463\nNonce: 0",
    "signature": "0x282dbd15e2ef7091c8599ce1073e7c0f94cd7a02526b6bc43b84f01f190b457047b34e0d3bb63797872dffa106f33f914d5e6ff6d2e978f39944c6af6efec7691b"
  }
}

Example Response

{
  "data": {
    "submitTransaction": {
      "transactionHash": "0x9aa26c9bfce628b160a43c155a12049c22c74276c28ca250df20df40f78baf1c"
    }
  }
}

Viewing Transactions

import { FC } from 'react'
import { useGetTransaction } from '@futureverse/asset-registry-react'
import { TransactionHash } from '@futureverse/asset-registry/types'

type Props = {
  transactionHash: string
}

export const TransactionStatus: FC<Props> = ({ transactionHash }) => {
  const { transaction } = useGetTransaction(
    { transactionHash: transactionHash as TransactionHash },
    {
      refetchInterval: (data) => (data?.status === 'PENDING' ? 5000 : false),
    },
  )

  if (!transaction) return null
  return (
    <div>
      <h4>Transaction Status: </h4>
      <pre>{JSON.stringify(transaction, undefined, 2)}</pre>
    </div>
  )
}

© 2023 -> ♾️