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

@candypay/sdk

v1.1.2

Published

A TypeScript SDK for effortlessly create NFT minting functions for Candy Machine v2 collections

Downloads

55

Readme

@candypay/sdk

CandyPay SDK lets you effortlessly create NFT minting functions for Candy Machine v2 collections. Simulate minting transactions for multiple use-cases like NFT collection launch, gasless mint and many more on Solana Blockchain!

Installation

npm install @candypay/sdk @project-serum/anchor

Setup

The entry point to the SDK is a CandyPay instance that will give you access to its API.

import { CandyPay } from "@candypay/sdk";

const candypay = new CandyPay();

Candy Machine module

The candyMachine module can be accessed via candypay.candyMachine() and provides the following methods:

mint

The mint method returns the transaction object with the all the required instructions for minting a Candy Machine v2 in the default way, where the end-user would pay the gas fees.

Parameters:

  • network: The cluster where the transaction would take place i.e either mainnet-beta or devnet
  • candyMachineId: The address of the Candy Machine
  • user: The public key of the end-user
  • rpc_url (optional): Custom RPC URL

Response:

  • transaction: The transaction object containing all the required instructions
  • blockhash: Blockhash which is being used in the transaction
  • lastValidBlockHeight: The last valid block height after which the transaction is declared expired
  • signers: Array of signers which should be passed while sending the transaction to the network
  • mint: The mint keypair which is used to sign the transaction

Example:

import { CandyPay } from "@candypay/sdk";
import * as anchor from "@project-serum/anchor";
import dotenv from "dotenv";
import base58 from "bs58";

dotenv.config();

const sdk = new CandyPay();
const connection = new anchor.web3.Connection(
  "https://metaplex.devnet.rpcpool.com"
);

const CANDY_MACHINE_ID = new anchor.web3.PublicKey(
  "GrVSy3ZRbuw5ACbwSEMsj9gULk9MW7QPK1TUYcP6nLM"
);
const PAYER = anchor.web3.Keypair.fromSecretKey(
  base58.decode(process.env.PAYER_SECRET_KEY!)
);

const { transaction, mint } = await sdk.candyMachine.mint({
  candyMachineId: CANDY_MACHINE_ID,
  network: "devnet",
  user: PAYER.publicKey,
});

const signature = await anchor.web3.sendAndConfirmTransaction(
  connection,
  transaction,
  [PAYER, mint]
);

console.log(`Signature - ${signature}`);

gasless

The gasless method returns the transaction object with the all the required instructions for minting a Candy Machine v2 in the gasless way, where the end-user doesn't need pay the gas fees.

Parameters:

  • network: The cluster where the transaction would take place i.e either mainnet-beta or devnet
  • candyMachineId: The address of the Candy Machine from which the NFT would to be minted
  • payer: The public key of the wallet which would pay the gas fees of the transaction
  • user: The public key of the end-user
  • rpc_url (optional): Custom RPC URL

Response:

  • transaction: The transaction object containing all the required instructions
  • blockhash: The blockhash which is being used in the transaction
  • lastValidBlockHeight: The last valid block height after which the transaction is declared expired
  • signers: Array of signers which should be passed while sending the transaction to the network
  • mint: The mint keypair which is used to sign the transaction

Example:

import { CandyPay } from "@candypay/sdk";
import * as anchor from "@project-serum/anchor";
import dotenv from "dotenv";
import base58 from "bs58";

dotenv.config();

const sdk = new CandyPay();
const connection = new anchor.web3.Connection(
  "https://metaplex.devnet.rpcpool.com"
);

const CANDY_MACHINE_ID = new anchor.web3.PublicKey(
  "GrVSy3ZRbuw5ACbwSEMsj9gULk9MW7QPK1TUYcP6nLM"
);
const PAYER = anchor.web3.Keypair.fromSecretKey(
  base58.decode(process.env.PAYER_SECRET_KEY!)
);
const USER = new anchor.web3.PublicKey(
  "2S9jKJEGKoVxR3xkEfFyGVrLwJj1H8xYjqtSP5LAX97x"
);

const { transaction, mint } = await sdk.candyMachine.gasless({
  candyMachineId: CANDY_MACHINE_ID,
  network: "devnet",
  payer: PAYER.publicKey,
  user: USER,
});

const signature = await anchor.web3.sendAndConfirmTransaction(
  connection,
  transaction,
  [PAYER, mint]
);

console.log(`Signature - ${signature}`);

NFT module

The nft module can be accessed via candypay.nft() and provides the following methods:

airdrop

The airdrop method allows you to airdrop certain NFT without having to create an NFT beforehand.

Parameters:

  • payer: The public key of the wallet which would pay gas fees of the transaction
  • owner: The public key of user to whom the NFT would be airdropped
  • network: The cluster where the transaction would take place i.e either mainnet-beta, devnet or testnet
  • metadata: The metadata regarding the NFT
  • rpc_url: Custom RPC URL

Response:

  • signature: The signature of the NFT airdrop transaction
  • accounts: The accounts related to the NFT airdrop transaction i.e mint account, metadata account, master edition account and token account
  • blockhash: The blockhash which is being used in the transaction

Example:

import { CandyPay } from "@candypay/sdk";
import * as anchor from "@project-serum/anchor";
import dotenv from "dotenv";
import base58 from "bs58";

dotenv.config();

const sdk = new CandyPay();

const PAYER = anchor.web3.Keypair.fromSecretKey(
  base58.decode(process.env.PAYER_SECRET_KEY!)
);
const USER = new anchor.web3.PublicKey(
  "2S9jKJEGKoVxR3xkEfFyGVrLwJj1H8xYjqtSP5LAX97x"
);

const { signature } = await sdk.nft.airdrop({
  metadata: {
    name: "DeGod",
    uri: "https://metadata.degods.com/g/4924.json",
    symbol: "DEGOD",
    collection: null,
    sellerFeeBasisPoints: 1000,
    creators: [
      {
        address: PAYER.publicKey,
        share: 100,
      },
    ],
    uses: null,
  },
  network: "devnet",
  owner: USER,
  payer: PAYER,
});

console.log(`Signature - ${signature}`);

Using the SDK with Next.js

Using our SDK with Next.js can sometimes run in build time error cause of Anchor library using the node native "fs" module. We highly recommend adding this export in next.config.js file before deployment:

module.exports = {
  webpack: (config, { isServer }) => {
    if (!isServer) {
      config.resolve.fallback.fs = false;
    }
    return config;
  },
};

Get in Touch