Skip to content

How to deploy a mintable TestNFT

Tobias Schubotz edited this page Dec 3, 2020 · 1 revision

This guide shows how to deploy a mintable TestNFT via Remix.

  1. Go to https://remix.ethereum.org/
  2. Click + in the file explorer to create a new file

image

  1. Enter a filename of your liking, e.g. TestNFT.sol
  2. Paste the following smart contract code:
// contracts/TestNFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/token/ERC721/ERC721.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/utils/Counters.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.2.0/contracts/utils/Strings.sol";

contract TestNFT is ERC721 {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() public ERC721("TestNFT", "TNFT") {
        _setBaseURI("https://www.google.com/search?q=");
    }   

    function mint() public returns (uint256) {
        return mintTo(msg.sender);
    }

    function mintTo(address to) public returns (uint256) {
        _tokenIds.increment();

        uint256 newItemId = _tokenIds.current();
        _mint(to, newItemId);
        _setTokenURI(newItemId, Strings.toString(newItemId));

        return newItemId;
    }
}
  1. Go to the "Compiler" section and hit "Compile". There should not be any error.

image

  1. Go to the "Deploy & run txs" section, select "Injected Web3". This will take your Metamask. Make sure Metamask is set to the desired network.

image

  1. Hit "Deploy" and sign with Metamask. This will deploy your contract. The address of your deployed contract will show up in the respective section:

image

A successful deploy to Rinkeby with verified contract code can be found here: https://rinkeby.etherscan.io/address/0x0263Ed323eb183F38621cC4d6FC7D767F6c51dC0

Clone this wiki locally