ERC-1155 NFT Project Template for Polygon, by Mas
- Verified contract on Polygonscan (Mumbai Testnet)
- Collection listed on OpenSea (Mumbai Testnet)
- Github repository
- Gasless transactions on Polygon (via meta-transactions)
- Compatable with Opensea's ERC-1155 metadata standards (uri() function differs slightly from the ERC-1155 standard).
- 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.
-
- git
- nodeJS/npm
- yarn
(optional; you can also just use
npm
/npx
if you prefer, but all steaps below will be usingyarn
) - 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)
-
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
-
Create free accounts and set up API keys for the Polygon and Mumbai (testnet) networks on the following the following platforms:
- Alchemy or Infura (Polygon RPC node services)
- Polygonscan
(for veriying your contract after deploying)
-
cp env .env
-
-
ALCHEMY_API_KEY
and/orINFURA_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))
-
-
- 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).
- For most NFT projects, it is preferrable to use decentralized storage options like IPFS and Arweave,
as opposed to centralized and self-hosted options.
-
- 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).
- On line 20, replace
- 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'ssupply
andtokenURI
values).
- Rename
-
- Testnet: Obtain $MATIC on the Polygon Mumbai testnet from a free faucet site:
- faucet.polygon.technology
- mumbaifaucet.com (you can get bonus $MATIC if you sign in with your Alchemy account)
- Mainnet: Obtain $MATIC on the Polygon POS chain. DYOR, but here are some options:
- directly from your cryptocurrency exchange, if they support it.
- the Polygon PoS chain bridge.
- cross-chain bridges like Across and Hop.
- Testnet: Obtain $MATIC on the Polygon Mumbai testnet from a free faucet site:
-
yarn hardhat test
-
- 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>
- Run the following code, replacing
- 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.
- In a web browser, go to Polygonscan and search for your contract,
or go directly to
- 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.
- Clean the cache and compile the contract.
-
-
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
- Deploy the contract using the deploy.js script to the Polygon network.
-
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 a separate terminal, start a local Hardhat node by running
- 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 π).
- Start the Remixd daemon by running
-
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.
- Verify the contract on Polygonscan on the Polygon mainnet.
-
- Hardhat Ethereum development environment is used for debugging, testing, and deploying contracts.
Runyarn 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.
- Remixd plug-in can be used to connect VSCode to the Remix IDE web app
(Hardhat will be listening on port 65522).
Further details on working with Hardhat and Remix together - When using Remix IDE, you may need to manually activate the REMIXD and/or WALLET CONNECT plug-ins manually in the PLUGINS MANAGER.
- Remixd plug-in can be used to connect VSCode to the Remix IDE web app
(Hardhat will be listening on port 65522).
contractURI()
function is used for implementing OpenSea's contract-level metadata.PermanentURI()
event is used for OpenSea's permanent URI recommendation.isApprovedForAll()
andsetApprovalForAll
are overridden to support OpenSea's Polygon integration and enable cost-free transactions for all users by approved operators.
OpenSea's ERC-1155 proxy address(0x207Fa8Df3a17D96Ca7EA4f2893fcdCb78a304101)
is set in the contract constructor.msgSender()
is overridden to support OpenSea's Polygon integration and enable meta-transactions.