# @triton-labs/wonka

> Wonka is a JS library meant that simplifies the minting process on Metaplex's CandyMachine.

Latest version **1.0.11** (published 2022-03-08) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @triton-labs/wonka
pnpm add @triton-labs/wonka
yarn add @triton-labs/wonka
bun add @triton-labs/wonka
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2022-03-08 |
| First published | 2022-01-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 18 |
| Unpacked size | 74.3 KB |
| Known vulnerabilities | 0 (+16 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 68 |
| Author | @0xZoZoZo, @kunal_modi |
| Maintainers | kunalmodi, zkhalapyan |
| Keywords | candy, machine, metaplex, nft, solana, crypto, mint |

## Links

- npm: https://www.npmjs.com/package/@triton-labs/wonka
- Repository: https://github.com/TritonLabs/Wonka
- Homepage: https://github.com/TritonLabs/Wonka#readme
- Issues: https://github.com/TritonLabs/Wonka/issues
- npm.io page: https://npm.io/package/@triton-labs/wonka

## Dependencies (18)

- [next](https://npm.io/package/next.md) ^12.0.7
- [react](https://npm.io/package/react.md) ^17.0.2
- [assert](https://npm.io/package/assert.md) ^2.0.0
- [arweave](https://npm.io/package/arweave.md) ^1.10.18
- [loglevel](https://npm.io/package/loglevel.md) ^1.8.0
- [react-dom](https://npm.io/package/react-dom.md) ^17.0.2
- [web-vitals](https://npm.io/package/web-vitals.md) ^1.0.1
- [@metaplex/js](https://npm.io/package/@metaplex/js.md) ^4.12.0
- [react-scripts](https://npm.io/package/react-scripts.md) ^3.0.1
- [@solana/web3.js](https://npm.io/package/@solana/web3.js.md) ^1.30.2
- [graphql-request](https://npm.io/package/graphql-request.md) ^4.0.0
- [@solana/spl-token](https://npm.io/package/@solana/spl-token.md) ^0.1.8
- [@project-serum/anchor](https://npm.io/package/@project-serum/anchor.md) ^0.18.2
- [@testing-library/react](https://npm.io/package/@testing-library/react.md) ^11.1.0
- [@testing-library/jest-dom](https://npm.io/package/@testing-library/jest-dom.md) ^5.11.4
- [@solana/wallet-adapter-base](https://npm.io/package/@solana/wallet-adapter-base.md) ^0.9.2
- [@testing-library/user-event](https://npm.io/package/@testing-library/user-event.md) ^12.1.10
- [@metaplex-foundation/mpl-token-metadata](https://npm.io/package/@metaplex-foundation/mpl-token-metadata.md) ^1.1.0

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.11 (latest) — 2022-03-08
- 1.0.10 — 2022-02-13
- 1.0.9 — 2022-02-13
- 1.0.8 — 2022-02-12
- 1.0.7 — 2022-02-03
- 1.0.6 — 2022-01-27
- 1.0.5 — 2022-01-20
- 1.0.4 — 2022-01-14
- 1.0.3 — 2022-01-12
- 1.0.2 — 2022-01-08
- 1.0.1 — 2022-01-07
- 1.0.0 — 2022-01-07

## README

# Wonka JS

`Wonka JS` is the easiest way to mint [Candy Machine](https://docs.metaplex.com/candy-machine-v2/introduction) NFTs through JS APIs. You can see an end to end example in [Next.js demo project](https://github.com/TritonLabs/wonka/tree/main/examples/next-js) as well as debug using the [command line testing tool](https://github.com/TritonLabs/wonka/tree/main/cli). 

![FI3xQ2FVcAQO3wK](https://user-images.githubusercontent.com/796815/153501801-7b3b5d27-a747-4df8-8cec-c5c7d2b233bb.jpeg)


Once you have [followed the instructions to upload your NFTs](https://docs.metaplex.com/candy-machine-v2/preparing-assets), 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](https://docs.metaplex.com/candy-machine-v2/mint-frontend). 

## Installation
`npm install @triton-labs/wonka`

## APIs

### Getting Machine State 
Returns info about currently available mints in Candy Machine, how many were already minted, how long is left for the auction, etc. 

```JS
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)
}
```

### Getting Existing Mints
Returns a list of all existing mints on the given candy machine. 

```JS
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)
}
```

### Minting a new NFT
Mints an NFT; you either get an error with a message or the ID of the mint in return. 

```JS
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)
}
```

### Fetching Mint Metadata
Sometimes you need to load one particular NFT's metadata, here is how you can do it:

```JS
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);
}
```

### Updating Mint Photo (Advanced)
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: 

1. You create an ArweaveUploader with a private key that has enough money in it for uploading files. 
2. You create a wonka with a provider that's attached to a wallet that has permission to update the NFT's metadata. 
3. You give Wonka a base64 encoded PNG and a mint address. That's it! 

```JS
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 }
    );
  }
```

### Storing Ids & Keys
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:

```JS
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](https://create-react-app.dev/docs/adding-custom-environment-variables/) and [Next.js .env](https://nextjs.org/docs/basic-features/environment-variables).

---
_Source: https://npm.io/package/@triton-labs/wonka · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
