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
Upload-Instagram - Auto Uploading Instagram Bot

###Instagram Uploading Bot### Download Python and Chrome browser pip install -r

byeonggeon sim 1 Feb 13, 2022
Sakura: an powerfull Autofilter bot that can be used in your groups

Sakura AutoFilter This Bot May Look Like Mwk_AutofilterBot And Its Because I Like Its UI, That's All Sakura is an powerfull Autofilter bot that can be

PaulWalker 12 Oct 21, 2022
Python script to harvest tweets with the Twitter API V2 Academic Research Product Track

Tweet harvester Python script to scrape, collect, and/or harvest tweets with the Twitter API V2 Academic Research Product Track. Important note: In or

Thomas Frissen 2 Nov 11, 2021
A Python Module That Uses ANN To Predict A Stocks Price And Also Provides Accurate Technical Analysis With Many High Potential Implementations!

Stox ⚡ A Python Module For The Stock Market ⚡ A Module to predict the "close price" for the next day and give "technical analysis". It uses a Neural N

Dopevog 31 Dec 16, 2022
Telegram 聊天機器人,追蹤momo降價、重新上架

簡介 price-tracker-bot is a telegram bot that can trace the price on momoshop. 功能 降價通知 上架通知 收藏商品 清空已收藏商品 顯示目前已收藏商品 Demo Bot Telegram bot search @momo_pr

92 Dec 28, 2022
Python3 script to dump employee information from XING API

XingDumper Python 3 script to dump company employees from XING API. Perfect OSINT tool ;-) The results contain firstname, lastname, position, gender,

LRVT 11 Dec 26, 2022
A simple python discord bot which give you a yogurt brand name, basing on a large database often updated.

YaourtBot A discord simple bot by Lopinosaurus Before using this code : ・Move env file to .env ・Change the channel ID on line 38 of bot.py to your #pi

The only one bunny who can dev. 0 May 09, 2022
Python Tool To Get The Date That Your Account Joined Instagram

Date-Joined-Insta Python Tool To Get The Date That Your Account Joined Instagram You Dont Need To Login Just Enter The UserName If Id Did Not Work Ins

A B D U L L A H . 1 Dec 21, 2021
A multi exploit instagram exploitation framework

Instagram Exploitation Framework About IEF Is an open source Instagram Exploitation Framework with various Exploits that could be used to mod your pro

Instagram Exploitation Framework - BirdSecurity 1 May 23, 2022
Cogs version of iso6.9 with the help of thatOneArchUser

iso6.9-cogs (debloated) This is a cogs version of iso6.9 by αrchιshα#5518. iso6.9 is a Discord bot written in Python and is used to make your Discord

Kamilla Youver 2 Jun 10, 2022
Python library for using SMS.ir web services

smsir smsir is a Python library for using SMS web services www.sms.ir Installation Use the package manager pip to install smsir. pip install smsir Usa

mohammad reza 2 Oct 14, 2022
Crud-python-sqlite: used to manage telephone contacts through python and sqlite

crud-python-sqlite This program is used to manage telephone contacts through python and sqlite. Dependencicas python3 sqlite3 Installation Clone the r

Luis Negrón 0 Jan 24, 2022
Most Powerful Chatbot On Telegram Bot

About Hello, I am Lycia [リュキア], An Intelligent ChatBot. If You Are Feeling Lonely, You can Always Come to me and Chat With Me! How To Host The easiest

RedAura 8 May 26, 2021
Automating whatsapp with python

whatsapp-automation Automating whatsapp with python used on this project pyautogui pywhatkit pyttsx3 SpeechRecognition colorama embedded in python tim

Miguel 60 Nov 21, 2022
Telegram Bot to learn English by words and more.. ( in Arabic )

Get the mp3 files Extract the mp3.rar on the same file that bot.py on install requirements pip install -r requirements.txt #Then enter you bot token

Plugin 10 Feb 19, 2022
A quick and dirty script to scan the network, find default credentials on services and post a message to a Slack channel with the results.

A quick and dirty script to scan the network, find default credentials on services and post a message to a Slack channel with the results.

Security Weekly 11 Jun 03, 2022
SickNerd aims to slowly enumerate Google Dorks via the googlesearch API then requests found pages for metadata

CLI tool for making Google Dorking a passive recon experience. With the ability to fetch and filter dorks from GHDB.

Jake Wnuk 21 Jan 02, 2023
Open Resource Calculator Module for Python

Calculator Module for Python By White Night Install #

White_Night_awa 4 Aug 22, 2022
PlaylistAudioBot - Telegram playlist download bot with ytdl

Telegram PlaylistAudioBot PlaylistAudioBot: 🇬🇧 Telegram playlist download bot

Hüzünlü Artemis [HuzunluArtemis] 14 Jul 22, 2022
A discord.py extension for sending, receiving and handling ui interactions in discord

discord-ui A discord.py extension for using discord ui/interaction features pip package ▪ read the docs ▪ examples Introduction This is a discord.py u

34 Dec 29, 2022