Futureverse Asset Registry Core SDK
Installation
NPM:
npm install @futureverse/asset-registry --save
Yarn:
yarn add @futureverse/asset-registry
Usage
Create Schema
import { Wallet } from 'ethers'
import { AssetRegistry } from '@futureverse/asset-registry'
import { Namespace } from '@futureverse/asset-registry/types'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const assetRegistrySdk = new AssetRegistry({
url: 'https://ar.futureverse.app/graphql',
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress,
},
})
assetRegistrySdk.createSchema({
namespace: 'fv.test' as Namespace,
schema: '',
version: 0.1,
})
Asset Linking
import {
AssetRegistry,
AssetTransactionMessage,
ChainAddress,
Signature,
TransactionHash,
} from '@futureverse/asset-registry'
import { ARTM, STATEMENTS } from '@futureverse/artm'
import { Wallet } from 'ethers'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const boxerDid =
'did:fv-asset:5:evm:0x5085cc0236ae108812571eadf24beee4fe8e0c50:4132'
const asmGenTwoBrainDid =
'did:fv-asset:5:evm:0x51cea47135c93eee33a6c15c22ea3532aec0540a:375'
let nonce = 0
const assetRegistrySdk = new AssetRegistry({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
},
})
nonce = await assetRegistrySdk.nonceForChainAddress(
walletAddress as ChainAddress,
)
const artmMessage = new ARTM({
address: walletAddress,
statement: STATEMENTS.OWNERSHIP,
nonce: nonce,
})
const operation = 'create'
artmMessage.operations = [
{
type: 'asset-link',
action: operation,
args: ['equipWith_asmBrain', boxerDid, asmGenTwoBrainDid],
},
]
const signature = await wallet.signMessage(artmMessage.getMessageToSign())
const input = {
signature: signature as Signature,
transaction: artmMessage.message as AssetTransactionMessage,
}
const response = await assetRegistrySdk.submitTransaction(input)
const transactionStatus = await assetRegistrySdk.transaction({
transactionHash: response.transactionHash as TransactionHash,
})
Create off-chain Asset
import { AssetRegistry } from '@futureverse/asset-registry'
import { Wallet } from 'ethers'
import { v4 as uuidv4 } from 'uuid'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const CREATOR_ID = '72fe2ff1-5f69-40e3-90b3-5335c7126552'
const assetRegistrySdk = new AssetRegistry({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
},
})
const creatorCollectionId = uuidv4()
const sftInput = {
creatorCollectionId: creatorCollectionId,
creatorId: CREATOR_ID,
}
const response = await assetRegistrySdk.registerOffChainAsset(sftInput)
const tokenId = uuidv4()
const creatorCollectionId2 = uuidv4()
const nftInput = {
creatorCollectionId: creatorCollectionId2,
creatorId: CREATOR_ID,
tokenId: tokenId,
}
const response2 = await assetRegistrySdk.registerOffChainAsset(nftInput)
Get Asset Tree
import { AssetRegistry } from '@futureverse/asset-registry'
import {
CollectionId,
} from '@futureverse/asset-registry/types'
import { Wallet } from 'ethers'
const GQL_API_URL = 'http://localhost:8080/graphql'
const domain = '<domain for the authentication>'
const origin = '<origin for the authentication>'
const chainId = 5
const wallet = Wallet.createRandom()
const walletAddress = wallet.address
const boxerDid =
'did:fv-asset:5:evm:0x5085cc0236ae108812571eadf24beee4fe8e0c50:4132'
const [_did, _fvAsset, chainId, chainType, contractAddress, tokenId] = boxerDid.split(':')
const assetRegistrySdk = new AssetRegistry({
url: GQL_API_URL,
auth: {
sign: async (message) => {
return await wallet.signMessage(message)
},
storage: {
set: (key: string, value: string) => localStorage.setItem(key, value),
get: (key: string) => localStorage.getItem(key),
},
domain,
origin,
chainId,
walletAddress: walletAddress,
}
})
const collectionId = `${chainId}:${chainType}:${contractAddress}` as CollectionId
const assetTree = await ar.getAssetTree({
tokenId
collectionId
})
const paths = assetTree?.paths
const clothingAssetTree = assetTree.getPath('http://schema.futureverse.com#equippedWith_accessoryClothing')
Requirements