Skip to content

ERC-1155 & ERC-2981 NFT template project, optimized for Polygon and OpenSea marketplace

License

Notifications You must be signed in to change notification settings

themasmedia/erc-1155-nft-project-template-for-polygon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ERC-1155 NFT Project Template for Polygon, by Mas

A sample deployment of this project can be referenced in the following links:


Marketplace Features:

Featured Extensions:

  • Tokens are Burnable by their repspective owners (both individually and by batch).
  • Transactions on the contract are Pausable by the contract owner, if needed.
  • Supply and Metadata URI are set unqiuely and permanently per token ID by the contract owner.
    This is to allowe editions for new token IDs to be minted in the future, free of the psuedo folder-like ERC1155.url/{tokenId} restriction
    (useful for metadata on decentralized storage where maintaining a folder/file structure is difficult).
  • Marketplace support for universal Royalty standards (ERC-2981).
    Royalties can be set uniquely per token ID, or default to the royalty info set in the contract constructor.

Supported Token Standards:

Instructions:

  1. If you haven't done so already, install the following:

    • git
    • nodeJS/npm
    • yarn (optional; you can also just use npm/npx if you prefer, but all steaps below will be using yarn)
    • nvm (optional; Managing your version of nodeJS for each project is a good practice)
    • VSCode (optional; recommended for the extensions)
    • Metamask (or similar wallet pletform, preferably with hardware wallet support, for connecting to dApps)

  2. Clone the project:

    git clone https://github.com/Masangri/erc-1155-nft-project-template-for-polygon.git
    cd erc-1155-nft-project-template-for-polygon
    yarn install
    

    If you are using nvm or another Node version manager, be sure to activate it before installing the package. For example:

    git clone https://github.com/Masangri/erc-1155-nft-project-template-for-polygon.git
    cd erc-1155-nft-project-template-for-polygon
    nvm install --lts
    nvm use --lts
    yarn install
    
  3. Create free accounts and set up API keys for the Polygon and Mumbai (testnet) networks on the following the following platforms:

  4. Copy the env file and rename it to .env:

    cp env .env
    
  5. Set the following environment variables by editing the following fields in the .env file:

    • ALCHEMY_API_KEY and/or INFURA_API_KEY (API key token for your Alchemy and/or Infura accounts, respectively)
    • POLYGONSCAN_API_KEY (API key token for your Polygonscan account)
    • OWNER_PRIVATE_KEY (account to deploy the contract from - never reveal your seed phrase and/or private key(s) for your account(s))
    • PROJECT_NAME (the human-readable name of your project)
    • PROJECT_SYMBOL (the ticker symbol for your project (limiting it to 3-4 characters is recommended))
    • ROYALTY_FRACTION (the default royalty in basis points (1% = 100 bips) for secondary sales (you can always update this after deploying the contract))

  6. Upload metadata content:

    • For most NFT projects, it is preferrable to use decentralized storage options like IPFS and Arweave, as opposed to centralized and self-hosted options.
      Platforms like Pinata & NFT.STORAGE, and ardrive are solid code-free options for IPFS and Arweave, repectively.
    • Upload the metadata files. (JSON metadata & media content files - see OpenSea's metadata standards and the many NFT tutorials online for more info).
    • Optional: Upload a properly formatted JSON file if you are implementing OpenSea's contract-level storefront metadata (see contractURI() in the Technical Notes Contract section).

  7. Edit the following file names and hard-coded values in contracts/:

    • Rename ERC1155TestProject.sol to the same value set for <PROJECT_NAME> in Step 5 above.
    • In the newly renamed <PROJECT_NAME>.sol contract, change the following:
      • On line 20, replace ERC1155TestProject with <PROJECT_NAME>
      • If you uploaded contract-level storefront metadata in Step 6 (see contractURI() in the Technical Notes Contract section):
        • Edit line 73 to return the URI string to your contract-level metadata.
        • If you didn't utilize this feature, you can comment out or remove the contractURI() function altogether (lines 63-74).
    • Optional: Update the test/data.json file with your own metadata content uploaded in Step 6:
      • Edit the value on line 2 to match the URI string to your contract-level metadata.
      • Replace the object(s) inside tokenData with your own metadata (including each object's supply and tokenURI values).

  8. Fund your Polygon account(s):

    • Testnet: Obtain $MATIC on the Polygon Mumbai testnet from a free faucet site:
    • Mainnet: Obtain $MATIC on the Polygon POS chain. DYOR, but here are some options:
  9. Run the unittests on the default local Hardhat network successfully.

    yarn hardhat test
    
  10. Compile and deploy to the Polygon Mumbai testnet:

    • Clean the cache and compile the contract.
      • yarn hardhat clean && yarn hardhat compile
    • Run the deploy.js script to deploy the contract.
      • yarn hardhat run scripts/deploy.js --network polygonMumbai
      • Copy the contract's deploy address from the console output. It will be needed to verify and interact with the contract. πŸ‘‡
    • Verify the contract on Polygonscan.
      • Run the following code, replacing <CONTRACT_ADDRESS> with the address of your contract copied above:
      • yarn hardhat verify --constructor-args arguments.js --network polygonMumbai <CONTRACT_ADDRESS>
    • Once verified, interact with your contract on Polygonscan.
      • In a web browser, go to Polygonscan and search for your contract, or go directly to https://mumbai.polygonscan.com/address/<CONTRACT_ADDRESS>.
      • Under the Contract tab (which should have a green checkmark), connect Metamask and interact with your contract (mint tokens, edit royalties, etc.).
        You can also use Remix to easily interact with our contract, if your prefer.
    • Get your collection listed on OpenSea (testnet).
      • In a web browser, go to OpenSea's Get Listed page and select the Live on a testnet option, select Mumbai, and submit your contract address (it will require that at least one token has been minted on the contract).
      • If you implemented OpenSea's contract-level storefront metadata in Step 6, your OpenSea Storefront info will be automatically populated.
        If not, you will need to sert it up manually.
        Note that OpenSea does not natively support the ERC-2981 like other marketplaces, so you may need to set royalties manually.

  11. Upon successful completion of Step 10, we're ready to compile and deploy to the Polygon mainnet:

    • Double-check that all your settings are functioning as required on testnet on Polygonscan and OpenSea before proceeding.
      Make any necessary updates to environment variables for the mainnet contract, such as private key values.

    • Method 1 - VSCode & Hardhat - easier but arguably less secure:
      Deploy using the same method as Step 10, except on mainnet instead of testnet.

      • Deploy the contract using the deploy.js script to the Polygon network.
        • yarn hardhat run scripts/deploy.js --network polygon

    • Method 2 - VSCode, Hardhat, Remix IDE/Remixd Plug-In, and Injected Web3 (i.e. Metamask) - extra setup, but reployment requires explicit, secure approval:
      Deploy by connecting Hardhat to the Remix IDE, which features wallet support for contreact deployment.

      • Start the Remixd daemon by running yarn remixd -u https://remix.ethereum.org.
      • Go to remix.ethereum.org and click Connect to Localhost. You should see your directory appear as a workspace in the FILE EXPLORERS secion. Select contracts/<PROJECT_NAME>.sol.
      • In the SOLIDITY COMPILER section, check Enable Hardhat Compilation and select the Solidity compiler version set in your hardhat.config.js file (0.8.4).
        Click the πŸ”Compile button (the remix-compiler.config.js file be created and/or updated).
      • Optional: To test Hardhat and Remix on with your local HJarhat network:
        • In a separate terminal, start a local Hardhat node by running yarn hardhat node.
        • In the DEPLOY & RUN TRANSACTIONS section, set the ENVIRONMENT to Hardhart Provider, select <PROJECT_NAME>.sol under Contracts, enter the constructor arguments, and click Deploy.
        • Once deployed, you can interact with the contract through the UI (toggle accounts under ACCOUNTS).
      • In the DEPLOY & RUN TRANSACTIONS section, set the ENVIRONMENT to either:
        • Injected Web3 for browser-based wallets like Metamask.
        • Wallet Connect for mobile wallets like Trust.
          ...and connect the account you intend to deploy the contract with.
          Select <PROJECT_NAME>.sol under Contracts, enter the <PROJECT_NAME>, constructor arguments (<PROJECT_NAME>), and click Deploy.
      • Approve the transaction to deploy the contract in your connected wallet (no environment variable or hardcoded private key necessary 😎).

    • Once deployed successfully, verify your contract and get it listed on OpenSea just like we did on testnet, but with the following adjustments noted in bold.

      • Verify the contract on Polygonscan on the Polygon mainnet.
        • yarn hardhat verify --constructor-args arguments.js --network polygon <CONTRACT_ADDRESS>
        • Use Polygonscan on mainnet and search for your contract, or go directly to https://polygonscan.com/address/<CONTRACT_ADDRESS>.
      • Go to OpenSea's Get Listed page and select the Live on a mainnet option and select Polygon.

Technical Notes:

Development:

  • Hardhat Ethereum development environment is used for debugging, testing, and deploying contracts.
    Run yarn hardhat help for information on specific ommands.
  • Chai TDD/BDD library is used for running unittests.
  • Visual Studio Code IDE can be used for development locally and deploying contracts.
  • Remix IDE browser-based IDE can be used for development online and deploying contracts.

Network Settings:

Contract:

About

ERC-1155 & ERC-2981 NFT template project, optimized for Polygon and OpenSea marketplace

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published