-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2551d3d
commit c587cab
Showing
6 changed files
with
238 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ distribution_list.txt | |
*.jpg | ||
yarn.lock | ||
*.success | ||
*.error | ||
*.error | ||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import commandLineUsage from 'command-line-usage' | ||
import commandLineArgs from 'command-line-args' | ||
import { checkRequiredKeys, clusterCommandLine, convertOptionsToCamelCase, privateKeyCommandLine, validateFilesExistenceFromKeys } from './utils' | ||
import _ from 'lodash' | ||
import chalk from 'chalk' | ||
import { UpdateCandyMachineParams, init } from '../src/update-candy-machine' | ||
|
||
export default (argv: any) => { | ||
const createCollectionOptionList = [ | ||
privateKeyCommandLine, | ||
clusterCommandLine, | ||
{ | ||
name: 'candy-machine-address', | ||
alias: 'm', | ||
type: String, | ||
description: 'Candy nacgube address.', | ||
typeLabel: '{underline string}', | ||
group: 'required' | ||
}, | ||
{ | ||
name: 'collection-address', | ||
alias: 'a', | ||
type: String, | ||
description: 'Collection address.', | ||
typeLabel: '{underline string}', | ||
group: 'required' | ||
}, | ||
{ | ||
name: 'quantity', | ||
alias: 'q', | ||
type: Number, | ||
description: 'Quantity of items in the candy machine (items to be minted).', | ||
typeLabel: '{underline number}', | ||
group: 'required' | ||
}, | ||
{ | ||
name: 'item-name', | ||
alias: 'n', | ||
type: String, | ||
description: 'Name for the NFT to mint (uses autoincrement automatically).', | ||
typeLabel: '{underline string}', | ||
group: 'required' | ||
}, | ||
{ | ||
name: 'image-path', | ||
alias: 'P', | ||
type: String, | ||
description: 'NFT image path', | ||
typeLabel: '{underline file}', | ||
group: 'required' | ||
}, | ||
{ | ||
name: 'image-name', | ||
alias: 'N', | ||
type: String, | ||
defaultValue: '', | ||
description: 'NFT image name. Defaults to \'\'', | ||
typeLabel: '{underline string}' | ||
}, | ||
{ | ||
name: 'image-description', | ||
alias: 'D', | ||
type: String, | ||
defaultValue: '', | ||
description: 'NFT image description. Defaults to \'\'', | ||
typeLabel: '{underline string}' | ||
}, | ||
{ | ||
name: 'attributes', | ||
alias: 'A', | ||
type: String, | ||
defaultValue: '', | ||
description: 'NFT attributes with json format. Defaults to null', | ||
typeLabel: '{underline string}' | ||
}, | ||
] | ||
const createCollectionOptions = commandLineArgs(createCollectionOptionList, { argv }) | ||
|
||
const createCollectionDefinitions = [ | ||
{ | ||
header: 'NFT Candy Machine for POAPs', | ||
content: 'Updates a candy machine.' | ||
}, | ||
{ | ||
header: 'Required options', | ||
optionList: createCollectionOptionList, | ||
group: ['required'] | ||
}, | ||
{ | ||
header: 'Optional (with default values)', | ||
optionList: createCollectionOptionList, | ||
group: ['_none'] | ||
} | ||
] | ||
|
||
const requiredKeysPresent = checkRequiredKeys(createCollectionOptionList, createCollectionOptions.required) | ||
|
||
if (!requiredKeysPresent) { | ||
console.log(commandLineUsage(createCollectionDefinitions)) | ||
} else { | ||
|
||
const filesExistResult = validateFilesExistenceFromKeys( | ||
['private-key', 'image-path'], | ||
createCollectionOptions._all | ||
) | ||
|
||
if (filesExistResult.length > 0) { | ||
_.forEach(filesExistResult, x => { | ||
console.log(chalk.red(chalk.bold(`ERROR ====> ${x}`))) | ||
}) | ||
return | ||
} | ||
|
||
const data = convertOptionsToCamelCase(createCollectionOptions._all) | ||
|
||
init(data as UpdateCandyMachineParams) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { CandyMachine, CandyMachineConfigLineSettings, DefaultCandyGuardMintSettings, Metaplex, PublicKey, sol, toBigNumber } from "@metaplex-foundation/js"; | ||
import { nameLength, prefixUri, prefixUriLength } from "../settings" | ||
import { getKeypair, initializeMetaplex, uploadMetadata } from "./utils" | ||
import { Keypair } from "@solana/web3.js"; | ||
import chalk from "chalk"; | ||
|
||
const fs = require('fs') | ||
|
||
const updateCandyMachine = async (metaplex: Metaplex, keypair: Keypair, collectionMintPubkey: PublicKey, candyMachine: CandyMachine, itemName: string, quantity: number) => { | ||
const itemSettings: CandyMachineConfigLineSettings = { | ||
type: 'configLines', | ||
prefixName: itemName + ' #$ID+1$', | ||
nameLength: nameLength, | ||
prefixUri: prefixUri, | ||
uriLength: prefixUriLength, | ||
isSequential: true, | ||
} | ||
const candyMachineSettings = | ||
{ | ||
candyMachine: candyMachine, | ||
itemsAvailable: toBigNumber(quantity), | ||
itemSettings, | ||
sellerFeeBasisPoints: 0, | ||
maxEditionSupply: toBigNumber(0), | ||
isMutable: true, | ||
creators: [ | ||
{ address: keypair.publicKey, share: 100, verified: true }, | ||
], | ||
collection: { | ||
address: collectionMintPubkey, | ||
updateAuthority: keypair | ||
}, | ||
authority: keypair, | ||
price: sol(0), | ||
// guards: { | ||
// mintLimit: { id: 1, limit: 5 }, | ||
// } | ||
}; | ||
|
||
const updateCandyMachineOutput = await metaplex.candyMachines().update(candyMachineSettings, { commitment: 'finalized' }); | ||
return updateCandyMachineOutput.response.signature | ||
} | ||
|
||
const addNFTItems = async (metaplex: Metaplex, candyMachinePubkey: PublicKey, uri: string, quantity: number) => { | ||
const candyMachine = await metaplex | ||
.candyMachines() | ||
.findByAddress({ address: candyMachinePubkey }); | ||
const piecesUri = uri.split('/') | ||
const uriId = piecesUri[piecesUri.length - 1] | ||
const items: any[] = []; | ||
for (let i = 0; i < quantity; i++) { | ||
items.push({ | ||
name: '', | ||
index: i, | ||
uri: uriId | ||
}) | ||
} | ||
const { response } = await metaplex.candyMachines().insertItems({ | ||
candyMachine, | ||
items: items, | ||
}, { commitment: 'finalized' }); | ||
|
||
// console.log(`✅ - Items added to Candy Machine: ${candyMachinePubkey.toBase58()}`); | ||
// console.log(` https://explorer.solana.com/tx/${response.signature}`); | ||
|
||
} | ||
|
||
export interface UpdateCandyMachineParams { | ||
privateKey: string; | ||
cluster: string; | ||
collectionAddress: string; | ||
candyMachineAddress: string; | ||
quantity: number; | ||
itemName: string; | ||
imagePath: string; | ||
imageName: string; | ||
imageDescription: string; | ||
attributes?: string; | ||
} | ||
|
||
|
||
export const init = async (params: UpdateCandyMachineParams) => { | ||
const { privateKey, cluster, collectionAddress, candyMachineAddress, quantity, itemName, imagePath, imageName, imageDescription, attributes } = params | ||
|
||
const keypair = getKeypair(privateKey) | ||
const metaplex = initializeMetaplex(cluster, keypair) | ||
|
||
const candyMachineAddressPublicKey = new PublicKey(candyMachineAddress) | ||
|
||
const candyMachine = await metaplex | ||
.candyMachines() | ||
.findByAddress({ address: candyMachineAddressPublicKey }); | ||
|
||
|
||
candyMachine | ||
|
||
await updateCandyMachine( | ||
metaplex, keypair, new PublicKey(collectionAddress), candyMachine, itemName, quantity) | ||
|
||
const uriImage = await uploadMetadata( | ||
metaplex, | ||
fs.readFileSync(imagePath), | ||
imageName, | ||
imageDescription, | ||
attributes ? JSON.parse(attributes) : [] | ||
) | ||
await addNFTItems(metaplex, candyMachineAddressPublicKey, uriImage, quantity) | ||
|
||
console.log('✅ - ' + chalk.green(`Candy Machine Address: ${candyMachineAddress}`)); | ||
console.log('✅ - ' + chalk.green(`Candy Machine Address: ${candyMachineAddressPublicKey.toBase58()}`)); | ||
} |