npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bulkupload

v0.2.0

Published

Dynamically deploy and interact with NFT smart contracts on the blockchain

Downloads

2

Readme

contract-interface 🦍

Programmatically deploy and interact with NFT smart contracts. Deployed contracts and their NFTs are compatible with OpenSea, Rarible, and other markeplaces which support ERC-721 NFTs.

Bootstrapped with Hardhat and Solidity 0.8.9.

Installation

npm i @niftymints/contract-interface --save

Import class

import NFTManager from "@niftymints/contract-interface"

Supported functions

NFTManager

constructor (contractName: string = "NFT", rpcURL?: string, privateKey?: string)

Initialize the NFTManager using the name of the smart contract (default is "NFT"). Optionally also accepts rpc URL (Alchemy, Infura, etc.) and private key of wallet. If rpcURL and privateKey are left blank, use connect function to set a signer. Example:

const nft = new NFTManager("NFT", rpcUrl, privateKey);
 
// or without any arguments:
// const nft2 = new NFTManager();
// nft2.connect(signer);

connect (signer: Signer): NFTManager

Set the signer. Example:

nft.connect(signer);

deployContract (tokenName: string, tokenSymbol: string): Promise<string>

Deploy NFT.sol with the given constructor args. Returns the contract address. Example:

const contractAddress = await nft.deployContract("name", "symbol");

mintNFT (contractAddress: string, tokenURI: string, artist: string): Promise<string>

Mint a new NFT belonging to the given artist. Returns the transaction hash. Example:

const txHash = await nft.mintNFT(contractAddress, tokenURI, artist);

getTokenID (txHash: string, contractAddress?: string): Promise<string>

Get the ID of a minted NFT using the transaction hash. Optionally also accepts the contract address to make computation faster. Example:

const nftID = await nft.getTokenID(txHash, contractAddress);

txWait (txHash: string, confirmations: number): Promise<void>

Wait for block confirmations of the transaction. Example:

await nft.txWait(txHash, 5); // wait for 5 block confirmations

getContract (contractAddress: string): Promise<Contract>

Get the deployed instanced of a smart contract. Can be used to execute functions in the smart contract (ERC721URIStorage). Example:

const myContract = await nft.getContract(contractAddress);

await myContract.transfer(from, to, tokenID); // "transfer" function from smart contract

verify (contractAddress: string, ...args: any[]): Promise<void>

Verify the smart contract on the blockchain. Requires POLYGONSCAN_KEY environment variable to be set.

More 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("NFT", 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("NFT", 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)

Contributing 👋

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