Swap Accessories
Swap involves both unlinking and linking operations within a single transaction.
Asset link swap operation
[
{
type: 'asset-link',
action: 'delete',
args: [
// Operator
'equipWith_asmBrain',
// Opearand A: Boxer Asset ID
'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
// Opearand B: Brain Asset ID - 21
'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
],
},
{
type: 'asset-link',
action: 'create',
args: [
'equipWith_asmBrain',
'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
// Opearand B: Brain Asset ID - 22
'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:22',
],
},
]
Ownership check for link deletion
The user must own both assets to swap unless it is an off-chain asset, where only the creator of the child asset can swap. Swap between assets owned on a FuturePass account and FuturePass account owner EOA is allowed. As long as the ownership resolution is satisfied, accessories can also be swapped across chains.
import {
useGetARTM,
useSignAndSubmitTransaction,
} 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 linkOperation = {
type: 'asset-link',
action: 'create',
args: [
'equipWith_asmBrain',
'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:22',
],
}
const LinkAccessory = ({ address }) => {
const {
artm,
reactQuery: { refetch: getARTM },
} = useGetARTM(
{
address,
[],
},
{ enabled: false },
)
const { submitAsync, transaction } = useSignAndSubmitTransaction()
const submitARTM = async () => {
const { data: artm } = await getARTM()
if (!artm) {
return
}
artm.addOperation(unlinkOperation)
artm.addOperation(linkOperation)
return submitAsync({ artm })
}
return (
<button onClick={submitARTM}></button>
)
}
import { AssetRegister } from '@futureverse/asset-register'
import {
AssetTransactionMessage,
Signature,
chainAddressFromString,
} from '@futureverse/asset-register/types'
import { ARTM, STATEMENTS } from '@futureverse/artm'
const address = "YOUR_WALLET_ADDRESS"
const unlinkOperation = {
action: 'delete',
args: [
'equipWith_asmBrain',
'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21',
],
}
const linkOperation = {
action: 'create',
args: [
'equipWith_asmBrain',
'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000',
'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:22',
],
}
const ar = new AssetRegister({
...
})
const getARTM = async () => {
const nonce = await ar.nonceForChainAddress(chainAddressFromString(address))
return new ARTM({
operations: [unlinkOperation, linkOperation],
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 = { action: 'delete', args: [ 'equipWith_asmBrain', 'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000', 'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:21', ], } const linkOperation = { type: 'asset-link', action: 'create', args: [ 'equipWith_asmBrain', 'did:fv-asset:1:evm:0x6bca6de2dbdc4e0d41f7273011785ea16ba47182:1000', 'did:fv-asset:1:evm:0x1ea66a857de297471bc12dd12d93853ff6617284:22', ], } const artm = new ARTM({ operations: [unlinkOperation, linkOperation], 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": "0x0f35cc253abccfb69ecfba5a3fc6696a518aa5ad8bc1e19c71c73446269057c8" }
Last updated