Example code for interacting with solana anchor programs - candymachine

Overview

candypy

example code for interacting with solana anchor programs - candymachine

THIS IS PURELY SAMPLE CODE TO FORK, MODIFY, UNDERSTAND AND INTERACT WITH CANDYMACHINE USING ANCHORPY

I'll probably work on making this more resilient and fully featured, but at the moment, it's mainly to be used as an example of how to use anchorpy, and to understand candy machine better. the candymachine typescript client is amazing, but it couples together too many concerns - this is meant to interact with each instruction separately.

Interaction is primarily via command line to make it more explicit

some information about candymachine

  1. candymachine is an anchor program
  2. while a large portion of interacting with it is via anchorpy, there are still a few places where the interactions are directly through solanapy - mostly interactions with spl-token, spl-token-metadata

accounts used

There are 2 main accounts used by candymachine

  1. A config account which keeps track of total supply as well as rows [{ name: name, nft_metadata_uri: nft_metadata_uri}]
  2. A candymachine account which keeps track of the price and the date to go live

creating a candy machine involves the following steps at a high level

  1. creating the config account - using the create_config_account option. This is not an anchor interaction, but a vanilla interaction with the system program
  2. Initialization the config account (this is mainly allocating space for it based on the number of NFTs to be loaded, as well as paying rent) - using the initialize_config_account command (anchor)
  3. add NFTs into the config account (load the names and metadata urls for each nft as a separate row) - add_config_lines (anchor)
  4. create the main candymachine account (this is the second one). It will keep track of price, livedate, item count, treasury address which gets the payment
  5. update the candymachine account (this is optional, in case you want to change the date or the mint or the price)
  6. Mint. This is usually done through a browser client, but for illustration purposes the code also includes a mint command

step 1 - install the necessary stuff

pip install -r requirements.txt

also install the solana command line cli. its pretty useful

step 2 - configure solana cli for the devnet and get an airdrop of 5-10 sol

solana-keygen -o myfolder/wallet.json

solana config set -u d

solana airdrop 5 myfolder/wallet.json

run the last command a few times in case it fails. the key you just generted will serve the the payment key for configuring candymachine

step 3

create the config account

python main.py create_config_account myfolder/wallet.json 10

2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf

Note down the config accounts public address since you'll be using it for other commands

couple of things of note here-

  1. the space needed is calculated based on number of NFTs
  2. the rent exemption amount is in turn calculated by amount of space necesarry/ This can be optimized for a short term rent to make it easier, but i'm lazy for now
  3. the config accounts ownership is passed onto the CANDY_MACHINE_PROGRAM_ID

step 4

initialize the config account - store some basic data in it - authority, number of nfts, royalties, royalty split between creators

python main.py initialize_config_account myfolder/wallet.json ROBOTEST 10 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf 100

here -

  1. ROBOTEST is the symbol
  2. royalties are basis points (1/100 * percentage)
  3. creator array which is an option json (do a -h to check it out) which has a % split of which address gets what % of the royalty. This should total to 100 and candymachine ts check for this but thats not the point of this tutorial for now.

step 5

Add config lines, i.e. the actual NFTs you're going to load into the machine

python main.py add_config_lines myfolder/wallet.json 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf sample_files\nft_rows.json

These config lines are in the sample_files folder and the formation structure is a list of dicts-

[
  {"name": "rob #1",
 "uri": "https://gateway.pinata.cloud/ipfs/QmaPtzAKea1fcuaMhukiPsTVBEH7wwmMhDTxaN5Jz2zQq9/1.json"},
  {"name": "rob #2",
   "uri": "https://gateway.pinata.cloud/ipfs/QmaPtzAKea1fcuaMhukiPsTVBEH7wwmMhDTxaN5Jz2zQq9/2.json"},
  {"name": "rob #3",
   "uri": "https://gateway.pinata.cloud/ipfs/QmaPtzAKea1fcuaMhukiPsTVBEH7wwmMhDTxaN5Jz2zQq9/3.json"},
  {"name": "rob #4",
   "uri": "https://gateway.pinata.cloud/ipfs/QmaPtzAKea1fcuaMhukiPsTVBEH7wwmMhDTxaN5Jz2zQq9/4.json"},
  {"name": "rob #5",
   "uri": "https://gateway.pinata.cloud/ipfs/QmaPtzAKea1fcuaMhukiPsTVBEH7wwmMhDTxaN5Jz2zQq9/5.json"}
]

This sample has only 5 NFTs. It's possible to edit the code and upload the NFTs in batches, but since this is primarily for learning purposes, I'm keeping it simple (hardcoded index). becuase the index is always 0, it'll overwrite with the new set of files in the sample_files folder. Also, you'll notice this has the uri's already. Yes. This code expects you have your NFT uploaded to arweave or ipfs first. Another reason I went down this route besides learning was to keep a clear separation between code interating with solana and code interacting with arweave, file storage

step 6

create the actual cnady machine account

python main.py initialize_candy_machine myfolder/wallet.json 0.5 now 10 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf ANAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q

"now" is s convenience ooption, but you want to pass the epoch timestamp of when you want the machine to go live 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf as you know is the config account address ANAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q in this case is the wallet that should hold treasury funds

step 7

candy machine can be optionally updated. as many times as you like. Its mainly the price and the live date python main.py update_candy_machine myfolder/wallet.json 0.33 now 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf

  • price
  • time (epoch)
  • config address

#step 8 This is actually the most complex part. Here is what's happening when you're minting an NFT

NON ANCHOR INSTRUCTIONS

  1. IMPORTANT: this is from a client side, so you would preferably want to configure another wallet + airdrop some sol in it.
  2. you create a new NFT token
  3. you create an associated token account derived from your main address to "hold" the NFT
  4. you allocate some default mint space for the account (based on some constants) - rent exempt amount because these need to be permanent
  5. you add approval for the candymachine to transfer the NFT out of your wallet, modify it and return the NFT token (now with metadata populated

Anchor insturctuions

  1. The ancor mint command doesn't take any args and just takes a list of accounts and signatures

python main.py mint myfolder/client-wallet.json 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf ANAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q NAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q

myfolder/client-wallet.json is the new wallet creator for client side config address - same old, 2yeCtaKgESShtnDWdH24EuhZLrfnkVoHk9t3WmmnJcaf ANAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q - treaury address ANAwyQU9HCZXaKkypAHkvTGzDEDGvVsHxto7jLhenp7q - authority

step 8

once this is done, you can simply check the balance of your accont spl-token accounts --owner Token Balance

3W5RhXSBs5zyRpqeGUrC4xrN3ppNnRdBeYDYU3X1bhrp 1

Owner
dubbelosix
dubbelosix
dubbelosix
Python client library for Postmark API

Postmarker Python client library for Postmark API. Gitter: https://gitter.im/Stranger6667/postmarker Installation Postmarker can be obtained with pip:

Dmitry Dygalo 109 Dec 13, 2022
Discord bots that update their status to the price of any coin listed on x.vite.net

Discord bots that update their status to the price of any coin listed on x.vite.net

5am 3 Nov 27, 2022
Grocy-create-product - A script supports the batch creation of new products in Grocy

grocy-create-product This script supports the batch creation of new products in

André Heuer 6 Jul 28, 2022
修改自SharpNoPSExec的基于python的横移工具 A Lateral Movement Tool Learned From SharpNoPSExec -- Twitter: @juliourena

PyNoPSExec A Lateral Movement Tool Learned From SharpNoPSExec -- Twitter: @juliourena 根据@juliourena大神的SharpNOPsExec项目改写的横向移动工具 Platform(平台): Windows 1

<a href=[email protected]"> 23 Nov 09, 2022
Analytics platform for Telegram Channels

Tele-Report Analytics platform for Telegram Channels 🚧 👷 Getting Started 1- Install redis and postgreSQL (it would be more generic in future, like u

2 Oct 11, 2022
A zero-dependency Python library for getting the Kubernetes token of a AWS EKS cluster

tokeks A zero-dependency Python library for getting the Kubernetes token of a AWS EKS cluster. No AWS CLI, third-party client or library (boto3, botoc

Chris Karageorgiou Kaneen 6 Nov 04, 2022
Import Notion Tasks to

Notion-to-Google-Calendar (1 way) Import Notion Tasks to Google Calendar NO MORE UPDATES WILL BE MADE TO THIS REPO. Attention has been put on a 2-way

12 Aug 11, 2022
Anti-league-discordbot - Harrasses imbeciles for playing league of legends

anti-league-discordbot harrasses imbeciles for playing league of legends Running

Chris Clem 2 Feb 12, 2022
This bot will delete messages containing blacklisted words in your telegram groups.

Profanity Detector Bot This bot will delete messages containing blacklisted words in your telegram groups. Made using ProfanityDetector.

Aditya 17 Oct 08, 2022
Paid Udemy Courses with Coupons

Freedemy Paid Udemy Courses with Coupons Steps to run pip3 install -r requirements.txt python3 free-courses.py Then you can click the Enroll Link and

GOKUL A.P 23 Dec 14, 2022
The successor of GeoSnipe, a pythonic Minecraft username sniper based on AsyncIO.

OneSnipe The successor of GeoSnipe, a pythonic Minecraft username sniper based on AsyncIO. Documentation View Documentation Features • Mojang & Micros

1 Jan 14, 2022
A Code that can make your Discord Account 24/7 on Voice Channels!

Voicecord Make your Discord Account Online 24/7 on Voice Channels! A Code written in Python that helps you to keep your account 24/7 on Voice Channels

Phantom 229 Jan 07, 2023
Represents a Lavalink client used to manage nodes and connections.

lavaplayer Represents a Lavalink client used to manage nodes and connections. setup pip install lavaplayer setup lavalink you need to java 11* LTS or

HazemMeqdad 37 Nov 21, 2022
A simple fun discord bot using discord.py that can post memes

A simple fun discord bot using discord.py * * Commands $commands - to see all commands $meme - for a random meme from the internet $cry - to make the

Dice Flip 2 Dec 20, 2021
Davide Gallitelli 3 Dec 21, 2021
PaddleOCR推理的pytorch实现和模型转换

PaddleOCR2Pytorch 简介 ”真·白嫖“PaddleOCR 注意 PytorchOCR由PaddleOCR-2.0rc1+动态图版本移植。 特性 高质量推理模型,准确的识别效果 超轻量ptocr_mobile移动端系列 通用ptocr_server系列 支持中英文数字组合识别、竖排文本

519 Jan 08, 2023
A combination between python-flask, that fetch and send data from league client during champion select thanks to LCU

A combination between python-flask, that fetch data and send from league client during champion select thanks to LCU and compare picked champs to the gamesDataBase that we need to collect using my ot

Anas Hamrouni 1 Jan 19, 2022
Automatically kick deleted accounts

AntiDeletedAccountsBot (ADAB) Automatically kick deleted accounts Based on uniborg, a pluggable asyncio Telegram userbot based on Telethon. Installati

Qwerty-Space 34 Jan 02, 2023
List of twitch bots n bigots

This is a collection of bot account names NamelistMASTER contains all the names we reccomend you ban in your channel Sometimes people get on that list

62 Sep 05, 2021