Giter Club home page Giter Club logo

nft-profile's Introduction

Minting an NFT with Tableland + Polygon

This tutorial shows developers how to use Tableland for NFT metadata in a two table composable deployment model, using Polygon + SQL. For a full walkthrough, check out the writeup here.

Overview

The goal of this project is to show developers how to use Tableland + Polygon for metadata. There are a number of scripts that read some metadata files hosted locally (in metadata and images). It walks through how to take the set of images, upload them to IPFS, and combine them with local metadata JSON files (which originally have empty image fields) into ERC721 compliant objects. Then, the metadata is parsed into SQL statements for Tableland usage, which are used in a hardhat deployment of a TwoTablesNFT smart contract. Polygon is used for deploying the tables and the NFT smart contract.

├── README.md
├── images
│   ├── 0.jpeg
│   └── 1.jpeg
├── contracts
│   └── TwoTablesNFT.sol
├── hardhat.config.js
├── metadata
│   ├── 0
│   └── 1
├── package-lock.json
├── package.json
├── scripts
│   ├── deployTwoTables.js
│   ├── prepareSql.js
│   ├── metadataProcessing.js
│   └── verifyTwoTables.js
└── test
│   └── test.js
└── .env

Namely, the project is broken into the following:

  • images => A couple of sample images, but any images/amount can be included -- these will be uploaded to IPFS. Note that these will be related to the NFT's tokenId.
  • metadata => The corresponding metadata files for each image, which lack the "image" field value (empty string by default). The metadata files will have their "image" values overwritten by the image's CID upon IPFS upload. These JSON files must have a 1:1 relationship to images, with matching names (e.g., 0.jpeg for the image, and 0 for the JSON, omitting the extension).
  • contracts => The NFT smart contract (TwoTablesNFT), which will mint tokens & allow for the baseURI to be set that points to the Tableland network. TwoTablesNFT is the "recommended" way to do things where two Tableland tables (main and attributes) are used and composed with SQL.
  • hardhat.config.js => Some useful deployment configs, including gateways to the proper Alchemy node provider on Polygon Mumbai testnets -- and also loading the private key from .env for live testnet deployment.
  • scripts:
    • metadataProcessing.js => Look for images in images, upload images to IPFS, parse the metadata files, write these CIDs to the corresponding JSON/object, and also, return the built object for metadata preparation.
    • prepareSql.js => Take the output from uploadMetadataToIpfs.js and build SQL statements.
    • deployTwoTables.js => Deploy the TwoTablesNFT contracts, using the output from prepareSql.js -- and set the baseURI & tokenURI to the Tableland gateway (testnet.tableland.network).
    • verifyTwoTables.js => Although optional, an additional script that can be used to verify a contract on Polygonscan.
  • test => Includes some simple chai tests with ethers as well, including testing out the tokenURI is correct.
  • .env => Private variables to store locally, so do not expose these publicly; examples are provided in .env.example

Setup

  1. Clone this repo to use the images and metadata files (and to view the final code).
  2. Export your private key and save it in a .env file as PRIVATE_KEY. Steps 3-5 will do something similar.
  3. Create an nft.storage account (here), an API key (here), and save it locally as NFT_STORAGE_API_KEY.
  4. Sign up for an Alchemy account (here) and save it as ALCHEMY_POLYGON_MUMBAI_API_KEY.
  5. Optionally, sign up for a Polygonscan account and save an API key as POLYGONSCAN_API_KEY.
  6. Run any of the scripts defined below, such as deploying to Polygon: npx hardhat run scripts/deploy.js --network polygon-mumbai

Example Output

The following details some of the deployed information from this tutorial using Polygon Mumbai:

Available Scripts

Compile the NFT smart contract

npx hardhat compile

Run hardhat tests, including validating the tokenURI works as expected

npx hardhat test

Deploy the smart contract locally, running the following in different shells. The deploy.js script uploads local files to IPFS and sets the CID to the NFT contract's baseURI.

Deploy to live testnets like Polygon Mumbai

npx hardhat run scripts/deploy.js --network polygon-mumbai

And Optionally, instead of verifying the contract in deployTwoTables.js, you can do:

npx hardhat run scripts/verifyTwoTables.js --network polygon-mumbai

nft-profile's People

Contributors

geastham avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.