Shyft
Start BuildingSupportWebsite
  • Welcome
    • 👋Introducing Shyft
    • 🏗️Start Building
  • Solana Infrastructure
    • 🚁Shyft RPCs
  • Yellowstone gRPC Network
    • Decoding gRPC Latency
    • ⚡gRPC Docs
      • Introduction
      • Authentication
      • Subscribe Requests
      • FAQ
      • Getting Started
        • Initializing the Yellowstone Client
        • Making a gRPC connection
        • Adding a Reconnection Mechanism
        • Modifying your Subscribe Request
        • Closing a gRPC Connection
      • Subscribing to Transactions
        • All Transactions of an address
        • Subscribing to all transactions of a Liquidity Pool
        • Subscribing to all transactions of multiple addresses
        • Subscribing to all transactions of a Token
      • Subscribing to Accounts
        • Account Updates for a Program
        • Account Updates for an Address
        • Account updates using memcmp
      • Streaming Blocks & BlocksMeta
        • Streaming Block Updates
        • Subscribing to BlocksMeta
      • Modifying & Unsubscribing
  • Solana defi data
    • DeFI APIs
      • Get Pool By Address
      • Get Pools By Token Pair
      • Get All Pools for a Token
      • Get Liquidity Details of a Pool
  • Callbacks
    • ☎️What are Callbacks?
      • Transaction Callbacks
      • Account Callbacks
    • 📔Callback APIs
      • Response Structure
      • List Callbacks
      • Register callback
      • Remove callback
      • 🔥Pause a callback
      • 🔥Resume a callback
      • Update Callbacks
      • Add Addresses
      • Remove addresses
  • Solana Super Indexers
    • 🌩️GraphQL APIs
      • Getting Started
      • Building Queries
      • Paginating Response
      • Applying Filters
      • Ordering and Sorting Data
    • 📀Case Studies
      • Tensor
        • Get Active Listings of a Wallet
        • Get Active Bids of a Wallet
        • Get Active Listings of a Collection
        • Get all Bids of a Collection
        • Get all Pools of a Margin Account
        • Get all Pools by Owner
      • Raydium
        • Get Pool By Address
        • Get Pools By Token Address
        • Get Pools Created Between Time
        • Get Pool Burn Percentage
        • Get Liquidity Details of a Pool
        • Get Pool and OpenBook Market Info
        • Get Token Supply Percentage In Pool
      • Orca Whirlpool
        • Get Pool by Address
        • Get Pool by Token Address
        • Get Positions for a Pool
        • Get Positions for a Wallet
        • Get Liquidity Details of a Pool
      • Kamino
        • Get Borrow Details of a Wallet
        • Get Deposit Details of a Wallet
        • Get Reserve Details
      • Cross Marketplace Queries
        • Get active listings across marketplaces for a wallet
        • Get listings for a collection across marketplaces
        • Get floor price of a collection
      • Cross Defi Queries
        • Fetch Liquidity Pools for Token
      • Native Staking
        • Get Stakes for a Wallet
        • Get Stakes For Validator
      • Governance/Realms
        • Get DAO Token Owners
        • Get Proposals For Governing Mint
        • Get All Proposals For DAO
        • Get DAO Treasury Info
        • Get All Active Proposals For Wallet
      • Meteora
        • Get All LB Position Pairs
        • Get Position of a User Wallet
        • Get Pool by Token Addresses
        • Get All Deposits for a User
        • Get All Withdraws for a User
        • Get All Fees Claimed by a User
        • Get All User Positions and Deposits for a Pool
        • Get All User Positions and Withdrawals for a Pool
      • Fluxbeam
        • Get Pool by Address
        • Get Pool by Token Addresses
      • Drift
        • Get User account for Delegate
        • Get User accounts based on authority
        • Get User details based on Referrer
        • Get Borrow/Deposit Amount for an User
        • Get PrepPositions for an User Account
        • Getting OrderId and userOrderId
        • Get OpenOrders for a User Account
      • 🔥Pumpswap
        • 🔥Get Pool by Address
        • 🔥Get Pool by Creator Address
        • 🔥Get Pools by Token Addresses
      • 🔥Raydium Launchpad
        • 🔥Get Bonding Curve Details by Pool Address
        • 🔥Get All Pools for a Creator
        • 🔥Get Pools by Token Addresses
        • 🔥Get Migration details of a Pool
  • Solana APIs
    • API Reference
    • Transactions
      • Parsed Transaction Structure
      • Transaction APIs
        • History
        • Parse Signature
        • Parse Multiple Signatures
        • Send
        • Send Multiple
    • NFT
      • 🔥Create Gasless
      • Create
      • Read All
      • Burn
      • 🔥Burn Multiple NFTs V2
      • Update
      • 🔥Create NFT from Metadata
      • 🔥Read Wallet Nfts
      • 🔥Read Selected NFTs
      • 🔥Get NFT Owners
      • 🔥Update NFT Metadata Uri
      • 🔥Update V2
      • Search
      • Transfer
      • Transfer Multiple NFTs
      • Mint
      • Read
    • Wallet
      • Get Balance
      • Get Token Balance
      • Get All Tokens Balance
      • Get Portfolio
      • Resolve Address
      • Get All Domains
      • Get Stake Accounts
    • Fungible Tokens
      • Create
      • Mint
      • Burn
      • 🔥Update
      • Get Token Info
      • Transfer
      • Airdrop
Powered by GitBook
On this page
  • Creating candy machine
  • Minting token from candy machine
  • Conclusion

Was this helpful?

  1. Tutorials

Creating custom NFT collections with Candy Machine

Last updated 2 years ago

Was this helpful?

Creating custom collections becomes very easy with the help of candy machine. Below is an example to create a candy machine in order to mint a collection of 50 identitcal NFTs and also different ways of minting them.

Creating candy machine

A candy machine is an object which stores the configuration for all the NFTs which will be minted for a collection. To create a candy machine we can use

We will be creating a candy machine which will be able to mint 50 identical NFTs and which can be minted with either SOL payment or SPL Token payment. The only prerequisite for creating a candy machine you will need a metaplex collection NFT which is owned by the candy machine creator. In this case we already have one hence we will be using that. The code sample below can be used to create this Candy machine configuration.

var myHeaders = new Headers();
myHeaders.append("x-api-key", "<api-key>");

var body = {
    "network": "devnet",
    "wallet": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY",
    "symbol": "IDT",
    "max_supply": 0,
    "royalty": 0,
    "collection": "7KnYuwbcG3EDLBnpUTovGN1WjpB1WvvyNuMgjRezG33s",
    "items_available": 50,
    "bulk_item_settings": {
        "name": "Identical #$ID+1$",
        "uri": "https: //some.uri/abc/path"
    },
    "groups": [
        {
            "label": "token",
            "guards": {
                "tokenPayment": {
                    "amount": 1000000,
                    "destination": "AUE3Z8m8HDg8fLaho1XcQzxmmM9bNwKkdLqqkWAdR5Et",
                    "mint": "4831mWZ5kJxer8VbLVfARG4jz7zgXKdwkDrGp5Lf4xbY"
                }
            }
        },
        {
            "label": "sol",
            "guards": {
                "solPayment": {
                    "amount": 0.5,
                    "destination": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY"
                },
            }
        }
    ]
};

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: JSON.stringify(body),
  redirect: 'follow'
};

fetch("{{url}}/candy_machine/create", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
{
    "success": true,
    "message": "Created a candy machine",
    "result": {
        "encoded_transaction": "AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo2l60KkpefynvQkOtk1QICWlhQKU0PdDIO/AYb3vykVFUZwga4kD9ObPzVQsA5gYVIFSXDLtcJ9nbYrO96fcHAgAHDGPjqzVIuCP/v6/WrvtBX/4zMJrKp+ecAZZ/cohLlP6LxwE8CX1CwXhVk7t25wPEZ8REo3aizvgTvSmAl9z8Kkhs63ZhsGvzRgYnRWIjNZRvMn4zhvztW753biZuLIOB3HvliK3XidXrjix4Ti+4WebUiWEC1b9ncQcGCFGdwlgrmGxaxqRBUGZQYzMUokINTdwxVB+x2NzO9RJhNMrpdbQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC9zxe9FsEN/+HjqovSGHaSVFBNyXP1FOtIdt0vDQngEUM0TL/e8u8g25DF0JRBZ01rXF+kL68aj0vrWFmka6HZd9hR1oE5nreowBoK6+huGhroE9cx0+Q3udOQxnkqh9q8hf8LWR+Em3McdMurEVO/KSfAdV6JPEZaZUt6s5K2S7FfJWoq7a/zPX9c2CSE9M1/P3+jgkanX2mxlJ5fdIysLcGWx49F8RTidUn9rBMPNWLhscxqg/bVJttG8A/gpRmYs9n+p3uBpCSgTfaQ+Ch5nuwO0M2ytBTNmQnn2PKuLBAoFAwEAAAWXAq+vbR8NmJvtCwEAAAIAAAAAAAAAAITXFwAAAABj46s1SLgj/7+v1q77QV/+MzCayqfnnAGWf3KIS5T+iwIAAABlYXJseQAGEAAAAAAAAABlzR0AAAAAY+OrNUi4I/+/r9au+0Ff/jMwmsqn55wBln9yiEuU/osBAAAAAAAAAC5gZx6TIhdZJYuPxnHU0UyPJlpV7YyyWP8J7Ly39OvHjLKc9Wg19q1TSnDAWFC7zChmLArhJIZjWU4uDSiYqRWR7jTvSLH4raSEbxD3jZh01V4mQgWEiiN0zDK9dunZnGxhdGUAAAICAAAAAAAAAGXNHQAAAABj46s1SLgj/7+v1q77QV/+MzCayqfnnAGWf3KIS5T+iwEBAAUCAAE0AAAAAGDdZwAAAAAAUgMAAAAAAACvIX/C1kfhJtzHHTLqxFTvyknwHVeiTxGWmVLerOStkgkLAQIAAAYIBwAECwWeAa+vbR8NmJvtAwAAAAAAAAAEAAAAR1JHUE0BAAAAAAAAAAABAQAAAGPjqzVIuCP/v6/WrvtBX/4zMJrKp+ecAZZ/cohLlP6LAGQAAREAAABHVVJER1JVT1AgIyRJRCsxJBoAAABodHRwczogLy9zb21lLnVyaS9hYmMvcGF0aCiuHkzKw6Dycppc1CtpTdLxLbZuFyp69sVsRBkB/YypCgUDAAEJAAiyKAq95IG6jA==",
        "candy_machine": "EPqDyRiGSiNVbeK3NQtSeXfpenfXMXniTBD7F3jfFkNj",
        "signers": [
            "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY"
        ]
    }
}

Here we can we see that we have created a candy machine with total 50 items. In order to not fill all the items as all the NFTs are identical in our case we have added the bulk_item_settings config.

Here the URI would be same for all NFTs which will point to the metadata json. In the name field we can see the special variable $ID+1$ . This is a special variable which will allow us to add dynamic number to our NFT mints. With this config the first NFT would be named Identical #1 the second would be Identical #2 and so on.

The groups config which is seen will help us for minting. In the groups config we have specified 2 groups. In the first groups named token whenever the user will mint a NFT from that group he will be charged 1 token (considering that the above token has 6 decimals) which will be sent to the destination. Here it is important to note that the destination address is should be the associated token account of the treasury account for that specific token. mint is the address of the required SPL token.

The second group is sol. Using this group while minting will transfer 0.5 SOL to the destination account address.

Running this api would return an encoded transaction which should be signed by the wallet address specified while calling the API.

Minting token from candy machine

For minting token from the above candy machine we would need to know the candy machine address, the collection NFT authority address and the address in which the NFT will be minted to.

var myHeaders = new Headers();
myHeaders.append("x-api-key", "<api-key>");

var body = {
    "network": "devnet",
    "wallet": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY",
    "authority": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY",
    "candy_machine": "EPqDyRiGSiNVbeK3NQtSeXfpenfXMXniTBD7F3jfFkNj",
    "mint_group": "token"
}

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: JSON.stringify(body),
  redirect: 'follow'
};

fetch("{{url}}/candy_machine/mint", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
var myHeaders = new Headers();
myHeaders.append("x-api-key", "<api-key>");

var body = {
    "network": "devnet",
    "wallet": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY",
    "authority": "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY",
    "candy_machine": "EPqDyRiGSiNVbeK3NQtSeXfpenfXMXniTBD7F3jfFkNj",
    "mint_group": "sol"
}

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: JSON.stringify(body),
  redirect: 'follow'
};

fetch("{{url}}/candy_machine/mint", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
{
    "success": true,
    "message": "Token minted from candy machine",
    "result": {
        "encoded_transaction": "AgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACUbDlwF1qqjzO4k/38SCzs1ZAEeJFh2MQ2pcdLAR7zXOU+W36NQi/sws4yTuPw7+ZDfTkAN5edJgQjRM/0dP0NAgANFmPjqzVIuCP/v6/WrvtBX/4zMJrKp+ecAZZ/cohLlP6LyyYtbb5lJTrm2weDgV1reN3AlIQTjRo8UdjLppL10EAvc8XvRbBDf/h46qL0hh2klRQTclz9RTrSHbdLw0J4BFWQilHTdPmvL1l/dOYrjFXVnxQi4ECWNTy45A4WwfywbOt2YbBr80YG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XZmKCsY4pAdP9mVeobKwncfFu9U5i86NVGo9heTL3",
        "signers": [
            "7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY"
        ]
    }
}

While creating candy machine we specified the groups which will be used for different forms of payment. In the above snippets we can see, while using the mint API, if we specify the mint_group as token then the NFT would be minted as per the guards specified in token group while creating the candy machine. The using the above snippet would mint an NFT and transfer 1 token to destination address (AUE3Z8m8HDg8fLaho1XcQzxmmM9bNwKkdLqqkWAdR5Et)specified while creating Candy machine.

For SOL payment the mint_group needs to set as sol. This will mint a NFT and transfer 0.5 SOL to destination address of 7iviPE2HZ15QCvHHCm8QzYdXKt9qReeT5P4aqSRAp7oY

The above examples would return an encoded transaction which has to be signed by the wallet address specified in the mint API body.

Conclusion

With this our NFT collection setup is complete. For every new mint the user has to call the API with new wallet address.

More details on create API can be found here:

More details on minting API can be found here:

https://docs.shyft.to/start-hacking/candy-machine#create-candy-machine
https://docs.shyft.to/start-hacking/candy-machine#create-candy-machine
https://docs.shyft.to/start-hacking/candy-machine#mint-nfts-from-candy-machine