JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q36125F

Package Exports

  • @niftymints/contract-interface
  • @niftymints/contract-interface/index.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@niftymints/contract-interface) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

contract-interface 🦍

Programmatically deploy and interact with NFT smart contracts. Deployed contracts and their NFTs are compatible with OpenSea, Rarible.

Bootstrapped with Hardhat and Solidity 0.8.9.

trackgit-views

Installation

npm i @niftymints/contract-interface --save

Import class

import NFTManager from "@niftymints/contract-interface"

Supported functions

NFTManager

  • constructor (rpcURL: string, privateKey: string) - Optionally accepts rpc URL (Alchemy, Infura, etc.) and private key of wallet. If left blank, use connect function to assign a signer.
  • connect (signer: Signer): Set the signer
  • deployContract (tokenName: string, tokenSymbol: string): Promise - Deploy NFT.sol with the given args. Returns the contract address.
  • mintNFT (contractAddress: string, tokenURI: string): Promise - Mint a new NFT. Returns the transaction hash.
  • verify (contractAddress: string, ...args: any[]) - Verify the smart contract on the blockchain. Requires POLYGONSCAN_KEY environment variable to be set.

Examples

Deploy a contract
import NFTManager from "@niftymints/contract-interface";

const rpcURL = "<rpc-url>";
const privateKey = "<wallet-key>";

async function deploy() {
    const nft = new NFTManager(rpcURL, privateKey);
    const address = await nft.deployContract("Test NFT", "TNFT");
}

async function depoyWithSigner(signer) {
    const nft = (new NFTManager()).connect(signer);
    const address = await nft.deployContract("Test NFT", "TNFT");
}
Mint NFT
import NFTManager from "@niftymints/contract-interface";

const rpcURL = "<rpc-url>";
const privateKey = "<wallet-key>";

async function mintNFT(tokenURI) {
    const nft = new NFTManager(rpcURL, privateKey);
    const address = await nft.deployContract("Test NFT", "TNFT");
    const txHash = await nft.mintNFT(address, tokenURI);
    
    console.log(txHash)
}

Local development

npm i                   # install
npx hardhat compile     # compile
npx hardhat test        # unit test

Deploy on-chain

Create a .env file at the root directory with the following variables:

  • POLYGONSCAN_KEY: Polygonscan API key [video tutorial]
  • ALCHEMY_PROD_URL: Alchemy project key (prod env) [video tutorial]
  • ALCHEMY_DEV_URL: Alchemy project key (dev env) [video tutorial]
  • PRIVATE_KEY_DEV: Crypto wallet account private key. You can request some MATIC tokens from the polygon faucet.
  • PRIVATE_KEY_PROD: Crypto wallet account private key. Can be the same as PRIVATE_KEY_DEV but I like to use two separate accounts for dev and prod.

Deploy to Polygon mumbai testnet

npx hardhat deploy --network mumbai_dev

Deploy to Polygon mainnet

npx hardhat deploy --network matic_prod

Note: Please ensure you have the minimum number of MATIC tokens in your wallet (roughly 0.008 MATIC, or $0.20 USD - see latest MATIC-USD rate)

Deploy to Ethereum mainnet (untested)

npx hardhat deploy --network eth_prod

Contributing 👋

Contributions are always welcome! Feel free to open any issue or send a pull request. For questions, please contact shanzid.com.