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!
npm install @candypay/sdk @project-serum/anchor
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();
The mint
module can be accessed via candypay.mint()
and provides the following methods:
The mint
method allows you to generate 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 Candy Machine has been deployed i.e eithermainnet-beta
ordevnet
candyMachineID
: The ID of the Candy Machinepayer
: The public key of the end-user
Response:
instructions
: An array of instructions required for gasless minting of the Candy Machinemint
: Mint keypair of the NFT
Example:
import { CandyPay } from "@candypay/sdk";
import * as anchor from "@project-serum/anchor";
const candypay = new CandyPay();
const payer = new anchor.web3.PublicKey(
"3DzHJzPZGBwp7uN5NSMDgQjLAo2qAF78XEMwacmnFDMk"
);
const { instructions, mint } = await candypay.mint.mint({
candyMachineID: "GrVSy3ZRbuw5ACbwSEMsj9gULk9MW7QPK1TUYcP6nLM",
network: "devnet",
payer,
});
The gasless
method allows you to generate 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 Candy Machine has been deployed i.e eithermainnet-beta
ordevnet
candyMachineID
: The ID of the Candy Machinepayer
: The public key of the wallet who would fund the gas feesuser
: The public key of the end-user
Response:
instructions
: An array of instructions required for gasless minting of the Candy Machinemint
: Mint keypair of the NFT
Example:
import { CandyPay } from "@candypay/sdk";
import * as anchor from "@project-serum/anchor";
const candypay = new CandyPay();
const payer = new anchor.web3.PublicKey(
"A9H9THrKpxUkusUpLQKmMsmG2eaLi2oR6xxzuPb7Rma2"
);
const user = new anchor.web3.PublicKey(
"3DzHJzPZGBwp7uN5NSMDgQjLAo2qAF78XEMwacmnFDMk"
);
const { instructions, mint } = await candypay.mint.gasless({
candyMachineID: "GrVSy3ZRbuw5ACbwSEMsj9gULk9MW7QPK1TUYcP6nLM",
network: "devnet",
payer,
user,
});
The nft
module can be accessed via candypay.nft()
and provides the following methods:
The airdrop
method allows you to airdrop certain NFT without having to create a NFT beforehand.
Parameters:
network
- The cluster where the transaction would be simulated i.e eithermainnet-beta
,devnet
ortestnet
payer
- The public key of the wallet which would fund the gas fees of the transactionowner
- The public key of the user to whom the NFT would be airdroppedmetadata
- Metadata of the NFT
Response:
signature
- Signature of the transactionmint
- Mint keypair of the NFTblockhash
- Blockhash which was used for 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 candypay = new CandyPay();
const payer = anchor.web3.Keypair.fromSecretKey(
base58.decode(process.env.PAYER_SECRET_KEY!)
);
try {
const { signature } = await sdk.nft.airdrop({
network: "devnet",
payer,
owner: new anchor.web3.PublicKey(
"A9H9THrKpxUkusUpLQKmMsmG2eaLi2oR6xxzuPb7Rma2"
),
metadata: {
name: "DeGod",
uri: "https://metadata.degods.com/g/4924.json",
symbol: "DEGOD",
collection: null,
sellerFeeBasisPoints: 1000,
creators: [
{
address: payer.publicKey,
verified: true,
share: 100,
},
],
uses: null,
},
});
} catch (err) {
console.log(err);
}
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;
},
};
- Twitter: @candypayfun
- Website: candypay.fun