@leda-mint-io/candymachine-client-sdk
Version:
Metaplex Candy Machine Client SDK
64 lines (63 loc) • 3.03 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCandyMachineCreator = exports.getMasterEdition = exports.getMetadata = exports.getAtaForMint = void 0;
const anchor_1 = require("@j0nnyboi/anchor");
const constants_1 = require("../constants");
/**
* Get the associated token account from a mint and the owner.
*
* @param mint The mint to get the associated token account of.
* @param buyer The owner of the associated token account.
* @returns The associated token account
*/
const getAtaForMint = (mint, buyer) => __awaiter(void 0, void 0, void 0, function* () {
return yield anchor_1.web3.PublicKey.findProgramAddress([buyer.toBuffer(), constants_1.TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], constants_1.SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID);
});
exports.getAtaForMint = getAtaForMint;
/**
* Get the mint metadata.
*
* @param mint The mint to get the metadata of.
* @returns The mint metadata.
* */
const getMetadata = (mint) => __awaiter(void 0, void 0, void 0, function* () {
return (yield anchor_1.web3.PublicKey.findProgramAddress([
Buffer.from("metadata"),
constants_1.TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
], constants_1.TOKEN_METADATA_PROGRAM_ID))[0];
});
exports.getMetadata = getMetadata;
/**
* Get the mint edition.
* @param mint The mint to get the edition of.
* @returns The mint edition.
*
**/
const getMasterEdition = (mint) => __awaiter(void 0, void 0, void 0, function* () {
return (yield anchor_1.web3.PublicKey.findProgramAddress([
Buffer.from("metadata"),
constants_1.TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
Buffer.from("edition"),
], constants_1.TOKEN_METADATA_PROGRAM_ID))[0];
});
exports.getMasterEdition = getMasterEdition;
/**
* Get the creator of a candy machine.
* @param candyMachine The candy machine to get the mint of.
* @returns The creator of the Candy Machine.
*/
const getCandyMachineCreator = (candyMachine) => __awaiter(void 0, void 0, void 0, function* () {
return yield anchor_1.web3.PublicKey.findProgramAddress([Buffer.from("candy_machine"), candyMachine.toBuffer()], constants_1.CANDY_MACHINE_PROGRAM_V2_ID);
});
exports.getCandyMachineCreator = getCandyMachineCreator;