Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@wonka-labs/wonka-js
Advanced tools
Readme
Wonka JS
is the easiest way to mint from Candy Machine and fetch NFTs through JS APIs. You can see an end to end example in Next.js demo project as well as debug using the command line testing tool.
For using Wonka's Solana NFT indexing APIs, checkout Windex Documentation.
Once you have followed the instructions to upload your NFTs, you can use functions below to build your mint flow:
mintCandyMachineToken(..)
getCandyMachineMints(..)
getCandyMachineState(...)
getMintMetadata(...)
updateMintImage(...)
These commands are useful if you need to build a custom facing front end, and don't want to rely on the Candy Machine Minting Site.
npm install @wonka-labs/wonka-js
Returns info about currently available mints in Candy Machine, how many were already minted, how long is left for the auction, etc.
const getCandyMachineState = async () => {
console.log("Getting candy machine state.")
const provider = ...;
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!;
const wonka = new Wonka(provider, candyMachineId)
const candyMachineState = await wonka.getCandyMachineState()
console.log(candyMachineState)
}
Returns a list of all existing mints on the given candy machine.
const getCandyMachineMints = async() => {
console.log("Getting candy machine mints...")
const provider = ...;
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!;
const wonka = new Wonka(provider, candyMachineId)
const candyMachineMints = await wonka.getCandyMachineMints()
console.log(candyMachineMints)
}
Mints an NFT; you either get an error with a message or the ID of the mint in return.
const mintCandyMachineToken = async(recipientWallet: PublicKey) => {
const provider = ...;
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!;
const wonka = new Wonka(provider, candyMachineId)
const candyMachineMintId = await wonka.mintCandyMachineToken(recipientWallet)
console.log(candyMachineMintId)
}
Sometimes you need to load one particular NFT's metadata, here is how you can do it:
const getMintMetadata = async(mintAddress: string) => {
const provider = ...;
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!;
const wonka = new Wonka(provider, candyMachineId)
const mintMetadata = await wonka.getMintMetadata(mintAddress)
console.log(`Fetched mint metadata:`);
console.log(mintMetadata);
// Can also fetch the data stored inside the metadata:
const metadataDataURIData = await fetch(mintMetadata.uri);
const metadataDataURIDataJSON = await metadataDataURIData.json();
console.log(`Fetched mint metadata's URI data:`);
console.log(metadataDataURIDataJSON);
}
This is a bit more advanced, but if you have a wallet with the update authority, you can actually update the NFT's png. Since this requires access to arweave's private key, it's probably better to create a backend API that uses these functions. Here is what's happening at a high-level:
const updateMintImage = async(mintAddress: PublicKey, b64image: string) => {
console.log("Getting mint metadata...")
const provider = ...;
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!;
const wonka = new Wonka(provider, candyMachineId)
const arweaveUploader = new ArweaveUploader(process.env.ARWEAVE_KEY!);
const txn = await wonka.updateMintImage(
b64image,
arweaveUploader,
provider.wallet,
mintAddress,
{ image_updated: true }
);
}
The question is where to store information like candy machine ID, etc. If you're using React or Next.js, you can easily use the .env file so that the code above looks more like:
const candyMachineId = process.env.NEXT_PUBLIC_CANDY_MACHINE_ID!; // For Next.js
const candyMachineId = process.env.REACT_APP_CANDY_MACHINE_ID!; // For React
Read more about these in the docs: React .env and Next.js .env.
By default, fetching NFTs by Wallet, Collection, or ID requires fetching a series of Solana accounts and external JSON metadata, which can be slow and bandwidth intensive. The Wonka Index (windex) is a backend cache that enables blazing fast metadata fetches. You can use the following queries to easily fetch NFTs. For more details, visit WINDEX.md.
To display all NFTs in a collection, you can query Windex by Candy Machine ID or Collection ID (the collection id is the first verified creator in the NFT's metadata).
const fetchNFTsByCandyMachine = async(candyMachineId: PublicKey) => {
const nfts = await Windex.fetchNFTsByCandyMachineID(candyMachineId, 20, Windex.DEVNET_ENDPOINT);
console.log(`Retrieved ${nfts.length} NFTs!`);
}
const fetchNFTsByCollection = async(collectionId: PublicKey) => {
const nfts = await Windex.fetchNFTsByCollectionID(collectionId, 20, Windex.DEVNET_ENDPOINT);
console.log(`Retrieved ${nfts.length} NFTs!`);
}
const fetchNFTsByWallet = async(walletAddress: PublicKey) => {
const nfts = await Windex.fetchNFTsByWallet(walletAddress, 20, Windex.DEVNET_ENDPOINT);
console.log(`Retrieved ${nfts.length} NFTs in ${walletAddress}'s wallet!`);
}
const fetchNFTsByMintAddress = async(mintAddress: PublicKey) => {
const nft = await Windex.fetchNFTByMintAddress(mintAddress, Windex.DEVNET_ENDPOINT);
if (!nft) {
console.log("nft not found!");
} else {
console.log(`Fetched ${nft.address}: ${nft.name}`);
}
}
FAQs
Wonka JS is the easiest way to mint and fetch NFTs through JS APIs.
The npm package @wonka-labs/wonka-js receives a total of 42 weekly downloads. As such, @wonka-labs/wonka-js popularity was classified as not popular.
We found that @wonka-labs/wonka-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.