Composing

Grouping of NFTs to create one NFT

Composing Assets / NFTs is the process of assigning owner of sub Assets / NFTs to a main Asset / NFT. The owner of the main NFT is then the beneficiary owner of the sub NFTs, but when the owner transfers the main NFT to another wallet, the sub NFTs go with it.

To compose two NFTs, they must have the same owner. Prior to composing them, the owner must approve a transfer of the sub NFT's token id to the Asset Contract.

await seller.invoke(
    txAssetContract, 
    'approve', 
    { to: txAssetContract.address, tokenId: toUint256WithFelts("1") }, 
    { maxFee: FEE}
)

As previously stated, composing the assets means assigning ownership of the sub NFT to the main NFT. This happens by calling a custom function as per the code below:

const txHash = await seller.invoke(
      txAssetContract, 
      "composeSubTokens", 
      { 
        tokenId: toUint256WithFelts("0"),
        subTypes: [starknet.shortStringToBigInt('type 1')],
        subTokenIds: [ toUint256WithFelts("1") ]
      },
      { maxFee: FEE}
    )

The result is that if the owner of the main NFT transfers it to another wallet, then both NFTs are transfered to the new owner.

Last updated