Unlink Accessories
Last updated
Last updated
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>}
</>
)
}
import { AssetRegister } from '@futureverse/asset-register/v2'
import {
AssetTransactionMessage,
Signature,
chainAddressFromString,
} from '@futureverse/asset-register/types'
import { ARTM, STATEMENTS } from '@futureverse/artm'
const address = "YOUR_WALLET_ADDRESS"
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 ar = new AssetRegister({
...
})
const getARTM = async () => {
const nonce = await ar.nonceForChainAddress(chainAddressFromString(address)).execute()[0] as number
return new ARTM({
operations: [unlinkOperation],
nonce,
address,
statement: STATEMENTS.ASSET_UPDATE,
})
}
const signAndSubmit = async () => {
const artm = await getARTM()
await ar.sign(artm)
const assetInput = {
transaction: artm.message as AssetTransactionMessage,
signature: artm.signature as Signature,
}
return ar.submitTransaction(assetInput)
}
signAndSubmit()
Get nonce.
query GetNonceForChainAddress($input: NonceInput!) {
getNonceForChainAddress(input: $input)
}
{
"input": {
"chainAddress": "0x2d2438c6281b5115733287fc279f854c868d3ee2"
}
}
Get message and signature through ARTM.
import { ARTM, STATEMENTS } from '@futureverse/artm'
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 artm = new ARTM({
operations: [unlinkOperation],
nonce,
address,
statement: STATEMENTS.ASSET_UPDATE,
})
Submit transaction
mutation SubmitTransaction($input: SubmitTransactionInput!) {
submitTransaction(input: $input) {
transactionHash
}
}
{
"input": {
"transaction": artm.message,
"signature": artm.signature
}
}
Check transaction status
query GetTransaction($transactionHash: TransactionHash!) {
transaction(transactionHash: $transactionHash) {
id
status
transactionHash
error {
message
code
}
}
}
{
"transactionHash": "0xb9d1822e1544e86c480aa66cb73f2cd90eabff3e097df7cdeabc88f0ac7f4f32"
}