Skip to content

Instantly share code, notes, and snippets.

@chadoh
Created November 11, 2020 22:09
Show Gist options
  • Save chadoh/13ec5626cde505a6f09541c62f96cee2 to your computer and use it in GitHub Desktop.
Save chadoh/13ec5626cde505a6f09541c62f96cee2 to your computer and use it in GitHub Desktop.

Image

In decentralized version

Given an image, in any file format, when you add it to IPFS (ipfs add), you get a content ID like "qm1"

In centralized version

Given an image, POST it to Infura or Piñata, and get back its IPFS content ID (should be familiar if you're used to using AWS S3 buckets).

Metadata JSON

Let's say you have a JSON file with the following metadata:

{
  image_cid: "qm1",
  name: "Cool Sword Bro",
  description: "This sword is super cool, wow",
}

When you add this to IPFS, you will get some IPFS content id like "qm2"

On-chain storage

NFT

Each token has the following fields:

part of the NEP4 standard:

  • id (auto-incremented)
  • owner (a NEAR account)

extra, arterra-only stuff:

  • group id

Could look into how OpenSea wants metadata returned and ensure that NFTs are returned in this format.

NFT Group

In addition to specific tokens, you have an "NFT group". Each NFT group has:

  • id (auto-incremented)
  • creator (a NEAR account)
  • metadata cid (not guaranteed to be unique for different NFT Groups)
  • max supply
  • minted supply

On-chain permissions

When minting an NFT:

  • Must provide group_id
  • Check that env::predecessor_account_id is NFT Group's creator OR in a list of admins
  • Check that minted_supply is less than max_supply

In your app

When saving data

  1. Make calls to Infura/Piñata to upload image & other metadata, get cid (content ID) of the final JSON file for the metadata
  2. Make a call to NEAR to mint this, passing in that cid

When fetching data

  1. Make call to NEAR to fetch NFT or NFT group
  2. Make call to Infura/Piñata to load content with returned metadata cids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment