Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anishde12020/use-candymachine
wip
https://github.com/anishde12020/use-candymachine
candymachine hacktoberfest hooks metaplex nfts react-hooks solana
Last synced: about 1 month ago
JSON representation
wip
- Host: GitHub
- URL: https://github.com/anishde12020/use-candymachine
- Owner: AnishDe12020
- License: mit
- Created: 2022-09-19T08:52:54.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-19T22:44:05.000Z (over 1 year ago)
- Last Synced: 2024-12-21T15:18:50.502Z (about 2 months ago)
- Topics: candymachine, hacktoberfest, hooks, metaplex, nfts, react-hooks, solana
- Language: TypeScript
- Homepage: https://use-candymachine.vercel.app
- Size: 785 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Use Candymachine Hook
`useCandymachine` is a [React Hook](https://reactjs.org/docs/hooks-intro.html) that provides a simple interface to interact with a [Candy Machine](https://docs.metaplex.com/programs/candy-machine/). It accepts a Candymachine ID (address) and a [Connection Object](https://solana-labs.github.io/solana-web3.js/classes/Connection.html) and then returns multiple functions and other state variables.
## Features
- Fetching a Candymachine
- Fetching nfts that belong to a Candymachine
- Pagination when fetching nfts that belong to a Candymachine
- A `mint` function that can be directly called to mint a NFT
- Cleaner code, things are a little here and there now. Let me know (via an issue) if you have any suggestions. Maybe I am going to split the main hook into multiple ones (and then have a main one) but didn't decide upon that yet.## Usage
First install the package:
With NPM -
```bash
npm install use-candymachine
```With Yarn -
```bash
yarn add use-candymachine
```### Simple Usage
```tsx
import useCandymachine from "use-candymachine";
import { useEffect } from "react";const Component = () => {
const {
page,
nfts,
candymachineMeta,
isFetchingMetadata,
isFetchingNFTs,
initialFetch,
nextPage,
prevPage
} = useCandymachine(
connection, // solana connection object
"AVSqKTyhvWB2gViNpaytGe3riRDjHGLEQ5q15JYKuHfT", // candy machine id
4, // number of nfts to display per page
);useEffect(() => {
initialFetch();
}, []);return (
{!candymachineMeta ? (
Fetching metadata
) : (
Number of items: {candymachineMeta.items.length}
)}
{!nfts ? (
Fetching NFTs
) : (
nfts.map((nft, index) =>{nft.name}
)
)}prevPage()}>Previous Page
Current page: {page}
nextPage()}>Next Page
)
}```
### Minting an NFT
```tsx
import useCandymachine from "use-candymachine";const Component = () => {
const {
mint,
isMinting,
} = useCandymachine(
connection, // solana connection object
"AVSqKTyhvWB2gViNpaytGe3riRDjHGLEQ5q15JYKuHfT", // candy machine id
4, // number of nfts to display per page
);return (
{
const nft = await mint();
console.log(nft);
}}
>
Mint
{isMinting &&Minting...
}
)
}```
## Contributing
If you want to suggest a new feature, open a [new issue with the feature request template](https://github.com/AnishDe12020/use-candymachine/issues/new?assignees=&labels=enhancement&template=feature_request.yml&title=%5BFEAT%5D%3A+). For bug reports, use the [bug report issue template](https://github.com/AnishDe12020/use-candymachine/issues/new?assignees=AnishDe12020&labels=bug&template=bug_report.yml&title=%5BBUG%5D%3A+).
Hacktoberfest note: This project is participating in Hacktoberfest. You may work on any open issue or create a new issue along with a pr. If someone is already working on the issue, actively, please do not hijack it. You can however reques the issue to be re-assigned to you if here hasn't been any activity for a while.
To make a pr, fork the repository, clone it, create a new branch that describes the new feature or the bug it is fixing. Then make the required changes, commit them (we strongly recommend that you follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification and gitmojis are welcome as well). The next step is to create a pull request and a maintainer will review it as soon as possible.
## Contact
E-mail: [[email protected]](mailto:[email protected])
Twitter: [@AnishDe12020](https://twitter.com/AnishDe12020)