Skip to content

Commit

Permalink
feat: produce CIDv1
Browse files Browse the repository at this point in the history
This ensures produced CIDs are more deterministic and future-proof.
Producing CIDv1 ensures the text representation looks the same on
subdomain gateways and in browser address bar.
  • Loading branch information
lidel committed Mar 19, 2021
1 parent 17cc573 commit 3ba81e6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/minty.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const { loadDeploymentInfo } = require('./deploy')
// different environments (e.g. testnet, mainnet, staging, production, etc).
const config = require('getconfig')

// ipfs.add parameters for more deterministic CIDs
const ipfsAddOptions = {
cidVersion: 1,
hashAlg: 'sha2-256'
}

/**
* Construct and asynchronously initialize a new Minty instance.
Expand Down Expand Up @@ -101,14 +106,14 @@ class Minty {
// 'ipfs://QmaNZ2FCgvBPqnxtkbToVVbK2Nes6xk5K4Ns6BsmkPucAM/cat-pic.png' instead of
// 'ipfs://QmaNZ2FCgvBPqnxtkbToVVbK2Nes6xk5K4Ns6BsmkPucAM'
const ipfsPath = '/nft/' + basename
const { cid: assetCid } = await this.ipfs.add({ path: ipfsPath, content })
const { cid: assetCid } = await this.ipfs.add({ path: ipfsPath, content }, ipfsAddOptions)

// make the NFT metadata JSON
const assetURI = ensureIpfsUriPrefix(assetCid) + '/' + basename
const metadata = await this.makeNFTMetadata(assetURI, options)

// add the metadata to IPFS
const { cid: metadataCid } = await this.ipfs.add({ path: '/nft/metadata.json', content: JSON.stringify(metadata)} )
const { cid: metadataCid } = await this.ipfs.add({ path: '/nft/metadata.json', content: JSON.stringify(metadata)}, ipfsAddOptions)
const metadataURI = ensureIpfsUriPrefix(metadataCid) + '/metadata.json'

// get the address of the token owner from options, or use the default signing address if no owner is given
Expand Down

0 comments on commit 3ba81e6

Please sign in to comment.