@allowlist/dev
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Allowlist.dev SDK + Contracts

The easiest and most-flexible library for adding Allowlists to Solidity smart contracts.

For a complete guide on installation and usage, visit https://allowlist.dev.

Quickstart

1. Add the Allowlist packages.

npm add @allowlist/dev

2. Generate your allowlist.json

allowlist gen winners.csv 
? Enter your BIP39 mnemonic seed phrase: ...

This will generate an allowlist.json file in the current directory, and tell you which signer addresses to use:

Generated the following allowlist groups:

Group:   0x12345...
Wallets: 1234

Note - if you need to generate a BIP39 mnemonic, use:

allowlist bip39

3. Add functions and modifiers to your Smart Contract

Add the mint groups to your contract, and use the allowlist helpers for your mint function.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "@allowlist/dev/contracts/AllowList.sol";
import "erc721a/contracts/ERC721A.sol";

contract MyNFT is ERC721A, AllowList {
    constructor() ERC721A("My NFT", "NFT") {
        _addAllowList(
            address(0x12345...), // group address
            0.1 ether,           // the mint price
            1672552800,          // start timestamp
            1675231200,          // end timestamp
            1                    // max per wallet
        );
    }

    function allowListMint(
        address _address,
        uint256 _count,
        bytes calldata _signature,
        uint256 _nonce
    ) 
      external 
      payable 
      useSignature(_address, _count, _signature, _nonce) 
    {
        _mint(_address, _count);
    }
}

4. Mint from your Frontend

Call the mint function from your frontend of choice.

Example with React + wagmi:

import { useAccount, useContract } from 'wagmi'
import { useSignature } from "@allowlist/dev"

const signatures = require("path/to/allowlist.json")
 
function MyComponent() {
  const contract = useContract({
    address: '0x...',
    abi: [ /* ... your abi ... */ ] 
  })
  const { address } = useAccount()
  const sig = useSignature(address)
  
  const handleMint = () => {
    if (!sig) return
    const amountToMint = 1 // or mint the full allotment of sig.n
    contract
      .allowListMint(address, amountToMint, sig.s, sig.n)
      .then((tx) => tx.wait())
      .then((receipt) => {
        console.log("Mint Successful, tx: ", receipt.transactionHash)
      })
      .catch((err) => {
        console.error("Mint Failed", err)
      })
  }

  return <>
    <button onClick={handleMint}>Mint</button>
  </>
}

Readme

Keywords

Package Sidebar

Install

npm i @allowlist/dev

Weekly Downloads

21

Version

0.2.2

License

MIT

Unpacked Size

55.7 kB

Total Files

18

Last publish

Collaborators

  • ian_