The merkle root and proof is only necessary in traid-based order. For other order type, just leave out this.
Merkle Root Calculation Algorithm
Suppose a user filters out a set of tokenIds according to its traits, and the token id array is [12,10,7,8,9,11,13]. Then it needs to sort the token id array and build a binary tree:
The merkleRoot is hash1234(hash12,hash34) and here is value its 0x72da2598329de27c7d20ea24372ca2a4732aaac2d9386467373baa7874b870f6.
MerkleProof
Suppose the target leaf is 7, then the merkle proof is [8, hash2(9,10), hash34(hash3,hash4)]. Suppose the target leaf is 10, then the merkle proof is [9, hash1(7,8), hash34(hash3,hash4)].
Generate Merkle Proof And Root
This is the example JS code to calculate merkle root and merkle proof.
Metadata to IPFS
Write tokenIds to a text file and upload it to IPFS.
Convert IPFS hash to bytes32
Fill merkleRoot to merkleData[0] and ipfsHash to merkleData[1]
This is the example JS code to convert the bese58 encoding ipfs hash to bytes32
Suppose tokenIds is [7,8,9,10,11,12,13], then the original ipfs hash is QmZHbCohMvg1Pcf6rbh21DBhkCb7qCkwb37QK8xf6HQP39, the bytes32 ipfs hash is 0xa2a7d9b6454df5a7f4809215f12cc347e9662a4cdcd69d83e8a0f2cf65e1ce4c.