Asset Link Operations

Asset links can only be executed through a transaction. This guide will specifically focus on creating these operations using the SDKs.

Prerequisite readings

Asset Register Transaction goes into detail about how to create and submit transactions, whereas, this guide will focus on the asset link operations in particular to help you build an asset tree.

In the following sections, we will focus on using the ARTM library to create and manipulate an ARTM and its operations.

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

import { Operation } from '@futureverse/artm'

const createAssetLinkOperation: Operation = {
    type: 'asset-link',
    action: 'create',
    args: [
        'equipWith_asmBrain',
        'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
        'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
    ],
}
  • The first argument corresponds to the path or the subject of the link.

  • The second argument is the parent asset. An asset can have 0 to many links as a parent.

  • The third argument is the child asset. An asset can have 0 or 1 link as a child.

The user must own the parent asset to delete links.

import { Operation } from '@futureverse/artm'

const deleteAssetLinkOperation: Operation = {
    type: 'asset-link',
    action: 'delete',
    args: [
        'equipWith_asmBrain',
        'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
        'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
    ],
}

You may have noticed that all the arguments look the same. This is because we have to be explicit with exactly which link we are deleting.

Sign and Send!

Using the above operations you can create an ARTM as follows:

import { ARTM } from '@futureverse/artm'
import { ethers } from 'ethers'

// Lets get you a wallet to get you started
const wallet = new ethers.Wallet(0xc367447789c3d98a0005c48b761ffe7d2802cea44dace8656033b15d90914c1d)

const artm = new ARTM({
    address: wallet.address,
    // Custom message to help the user understand the operation
    statement: "Equip your ASM Brain",
    operations: [
        createAssetLinkOperation,
        deleteAssetLinkOperation
    ],
    nonce: 0
})

artm.setSignature(wallet.signMessage('\x19Ethereum Signed Message:\n' + artm.message)

console.log(artm.verify()) // true

// Submit the transaction!

In the above transaction, we are creating and then deleting the link in the same transaction. This is completely fine to do so but there is no reason to perform it other than for demonstration purposes!

Note that any invalid operation will result in the failure of the entire transaction.

© 2023 -> ♾️