How To make an ERC- 721 NFT Participation Certificate for your event/webinar etc.

Pre- requisites-

  1. preferably An Linux/ macOS installed system
  2. basic knowledge of smart contracts and ERC-20 protocol
  3. Metamask installed into chrome browser.

Setting up the environment-

$ mkdir NFTCert&& cd NFTCert
$ npm init -y
npm install --save-dev @openzeppelin/contracts
npm install truffle

Getting the contract artifacts

$ npx truffle init
Unbox successful, sweet!
$ mkdir -p build/contracts/
$ cp node_modules/@openzeppelin/contracts/build/contracts/* build/contracts/
// migrations/2_deploy.js
// SPDX-License-Identifier: MIT
const ERC721PresetMinterPauserAutoId = artifacts.require("ERC721PresetMinterPauserAutoId");
module.exports = function(deployer) {
deployer.deploy(ERC721PresetMinterPauserAutoId, "My NFT","NFT", "https://my-json-server.typicode.com/taylor2325/NFTCert/tokens");
};
  1. “id” is the ID for the NFT you have published, it would be useful in minting the NFT.
  2. “description” is the description of the NFT, It would be shown as what this NFT is for etc.
  3. “external_url” points to the website if you want to add.
  4. “image” is the image an NFT would be showing. pinata is preferred for external image. In this project, our certificate is the image.
  5. “name” is the name of the NFT you want to give

Deploying to the Rinkeby testnet

  • An Infura project ID (or a public node provider of your choice). follow link here to make your new project ID
  • @truffle/hdwallet-provider installed (To install, simply write npm install @truffle/hdwallet-provider)
  • Configure truffle-config.js for Rinkeby network
  • A funded testnet account and mnemonic
const fs = require('fs');const HDWalletProvider = require('@truffle/hdwallet-provider');var mnemonic = ""; // Your personal mnemonicvar projectId = ""; // your Personal projectIDmodule.exports = {networks: {rinkeby: {provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${projectId}`),network_id: 4,       // Rinkeby's idgas: 8500000,gasPrice: 1000000000,  // 1 gwei (in wei) (default: 100 gwei)confirmations: 2,    // # of confs to wait between deployments. (default: 0)timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )},},mocha: {// timeout: 100000},compilers: {solc: {// version: "0.5.1",    // Fetch exact version from solc-bin (default: truffle's version)// docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)// settings: {          // See the solidity docs for advice about optimization and evmVersion//  optimizer: {//    enabled: false,//    runs: 200//  },//  evmVersion: "byzantium"// }}},db: {enabled: false}};

Deploy to Rinkeby

$ npx truffle console --network rinkeby
truffle(rinkeby)> migrate
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'rinkeby'
> Network id: 4
> Block gas limit: 10000000 (0x989680)
1_initial_migration.js=====================Deploying 'Migrations'---------------------
> transaction hash: 0x9008f27679da63b92289ae4e4eacfbd5558ceed7c7c7fe2a56ef4218a2d11fb5
> Blocks: 0 Seconds: 13
> contract address: 0x1CD15A3D13FA90F9607359F0D667C8f3c99D822a
> block number: 8875873
> block timestamp: 1625375314
> account: 0x993E6B1Cf39135Cd6BCdb87Ff9E6bab538035FF3
> balance: 16.035155549
> gas used: 193219 (0x2f2c3)
> gas price: 1 gwei
> value sent: 0 ETH
> total cost: 0.000193219 ETH
Pausing for 2 confirmations...
------------------------------
> confirmation number: 1 (block: 8875874)
> confirmation number: 2 (block: 8875875)
> Saving migration to chain.
> Saving artifacts
-------------------------------------> Total cost: 0.000193219 ETH2_deploy.js===========Deploying 'ERC721PresetMinterPauserAutoId'
------------------------------------------
> transaction hash: 0xece55d4302e9de76195318bdfa14be7ca36f2527a26ef1f2635290cd5f361cbe
> Blocks: 2 Seconds: 21
> contract address: 0xF3255e17dD5d9DD8885C3E25eF72bbdc13974F82
> block number: 8875878
> block timestamp: 1625375389
> account: 0x993E6B1Cf39135Cd6BCdb87Ff9E6bab538035FF3
> balance: 16.032520751
> gas used: 2589060 (0x278184)
> gas price: 1 gwei
> value sent: 0 ETH
> total cost: 0.00258906 ETH
Pausing for 2 confirmations...------------------------------> confirmation number: 1 (block: 8875879)
> confirmation number: 2 (block: 8875880)
> Saving migration to chain.
> Saving artifacts
-------------------------------------> Total cost: 0.00258906 ETHSummary=======> Total deployments: 2
> Final cost: 0.002782279 ETH

Minting our new NFT

truffle(rinkeby)> nft = await ERC721PresetMinterPauserAutoId.deployed()
undefined
truffle(rinkeby)> accounts
['0x993E6B1Cf39135Cd6BCdb87Ff9E6bab538035FF3',
'0xf92827b75548789f90F80bf490Bf00b4DBaACFd1',
'0x2F0dD71a474B35818058723C74D86D941ba94244',
'0x1b79D6b7586aA9a364A297468Ca701aD1425CF70',
'0x74a96ee51b99723DeDE2C389c094E1e193Fa62D8',
'0x0dd3986B3118B33840cC71840b33cA241968b08b',
'0xCeE9fF1eb2eC25A92851949F2DA0eE4510581BB2',
'0xA6dE1B45f9623908060F5654aF99BA5dAFbB80a3',
'0x4C1f6718Cd420eA237e2735B502B4d9613114DA4',
'0x2Ced4bB916f18CA52B3Df957a02fFa4b4cb74B82']
truffle(develop)> await nft.mint("0x993E6B1Cf39135Cd6BCdb87Ff9E6bab538035FF3")

Finishing up…

Last Thoughts…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store