Transactions

Modifications to asset links must be carried out via an Asset Register Transaction.

Submitting Transactions

Once you have created an ARTM and have signed it, you can submit it to the Asset Register

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>
  )
}

Viewing transaction by hash

Once a transaction is submitted, you can view its status by querying it. Transaction information will live forever, making it available for future auditing purposes.

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>
  )
}

Viewing transactions by address

You can view all transactions initiated by an address.

import { useGetTransactions } from '@futureverse/asset-register-react/v2'
import { ChainAddress } from '@futureverse/asset-register/types'

export const Transactions = () => {
  const { transactions } = useGetTransactions({
    address: '0x2D2438C6281B5115733287fC279f854c868D3ee2' as ChainAddress,
  })

  if (!transactions) return null

  return (
    <div>
      {transactions.map((tx) => (
        <div key={tx.id}>
          <div>{tx.transactionHash}</div>
          <div>{tx.status}</div>
        </div>
      ))}
    </div>
  )
}

Last updated

© 2023 -> ♾️