This project allows the user to easily deploy their own ERC721 contracts, as well as minting their own NFTs via IPFS using the terminal
Technology Stack: Javascript, Node.js, Solidity, Hardhat
This project was coded with the Hardhat SDK and Openzeppelin contracts.
Minter
: OwnableUpgradeable ERC721 contract to mint NFTsMinterFactory
: Factory contract that creates Minter instances.
This project was coded using Node version 16.3.0.
If you do not already have node installed, Download and install node.
git clone https://github.com/filswan/nft
cd nft
Run npm install
to install all dependancies.
Set up an .env file which stores your
information as environment variables.
An example config is given as .env.example for reference.
MUMBAI_URL
: Mumbai RPC to interact with the payment and minting smart contract. Get API key from AlchemyPRIVATE_KEY
: Your ETH wallet's private key used to pay for transactionsMCS_API
: Endpoint to interact with MCS APIFILSWAN_API
: Endpoint to interact with Filswan API
Deploy the Minter contract using npx hardhat deploy --name <COLLECTION_NAME> --symbol <TOKEN_TICKER>
.
Since Minter.sol
is an upgradeable smart contract, this script will deploy a proxy.
You can also add --network <NETWORK_NAME>
to specify which network to deploy to.
Currently, the default network is the Mumbai testnet
Additional parameters can be added to provide metadata for your collection
--desc
: Collection description--image
: URL of an image for your collection (preferably IPFS URI)--link
: An external link to your website (usually to provide more information about your NFT)--fee
: here you can set a trading fee for you NFTs (a value of 100 indicates a 1% fee)--recipient
: the address where the seller fees will be paid to
Store the contract address in the hardhat.config.js
with key contract
under the correct network.
Some tests are written under the ./test/
folder. These can be run using npx hardhat test --network hardhat
This option is provided for users who have many files to upload, note that these files will not be automatically paid for.
First you will need a csv file with the format fileName, filePath
fileName, filePath
file1, path/to/file1
file2, path/to/file2
Use command npx hardhat batchUpload --file <CSV_PATH>
to perform the batch upload.
These uploads will be staggered API calls with a default delay of 1000ms (1 second). The optional parameter --delay <ms>
can be included to set your own delay (recommended for large files).
Use command npx hardhat uploadMint --file <PATH>
. This script uses helper functions to:
- upload the file to MCS
- lock token payment (will need some USDC)
- generate metadata JSON
- upload metadata to MCS
- mint NFT
Optional params include --name <NFT_NAME> and --desc <NFT_DESCRIPTION>
The metadata will look like:
{
name: <NFT_NAME> // defaults to the name of file,
description: <NFT_DESCRIPTION>,
image: <READ_GATEWAY> + <IPFS_CID>,
attributes: [{trait_type: 'Size', value: <FILE_SIZE>}],
tx_hash: <LOCK_TOKEN_TX_HASH>
}
Alternatively, you can also use other commands for a step-by-step process.
- Use
npx hardhat upload --file <PATH>
to upload your file to MCS and lock token payment. - Use
npx hardhat mint --uri <IPFS_URI>
to generate NFT metadata, upload to MCS, and mint- Optional parameters include
--name <NFT_NAME>
and--desc <NFT_DESCRIPTION>
- Optional parameters include
Use npx hardhat help
to see all available tasks or npx hardhat help <TASK>
to see how to use a command.
Use command npx hardhat tokenURI --id <tokenID>
to retrieve the tokenURI of a minted NFT.
After minting, the NFT should be available to view on OpenSea (testnet).
You can search for your collection (your deployed contract) using the contract address here:
https://testnets.opensea.io/get-listed
Select the correct network and paste the contract address. Your collection will be opened on a new tab.
NFT metadata will take some time to load, Opensea will call the tokenURI function in the contract to refresh the metadata.