Skip to content

Instantly share code, notes, and snippets.

@0xPratik
Created December 30, 2022 14:11
Show Gist options
  • Save 0xPratik/137981f19dea9566f13d0841d507fe45 to your computer and use it in GitHub Desktop.
Save 0xPratik/137981f19dea9566f13d0841d507fe45 to your computer and use it in GitHub Desktop.
const createTrifle = async(
wallet: anchor.Wallet,
mint: anchor.web3.PublicKey,
constraintModel: anchor.web3.PublicKey,
) => {
const [masterKey] = await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("metadata"),
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
Buffer.from("edition"),
],
TOKEN_METADATA_PROGRAM_ID
);
console.log("Edition",masterKey.toString());
const [metadatakey] = await anchor.web3.PublicKey.findProgramAddress(
[
Buffer.from("metadata"),
TOKEN_METADATA_PROGRAM_ID.toBuffer(),
mint.toBuffer(),
],
TOKEN_METADATA_PROGRAM_ID
);
console.log("Metadata",metadatakey.toString());
let tokenAccount = await getAssociatedTokenAddress(
mint, // mint
wallet.publicKey // owner
);
let [trifleAddress] = await findTriflePda(mint, wallet.publicKey);
let [escrowAddress] = await findEscrowPda(mint, 1, trifleAddress);
const accounts : CreateTrifleAccountInstructionAccounts = {
mint: mint,
metadata: metadatakey,
tokenAccount:tokenAccount,
escrow:escrowAddress,
trifleAccount:trifleAddress,
constraintModel:constraintModel,
edition:masterKey,
trifleAuthority: wallet.publicKey,
systemProgram: anchor.web3.SystemProgram.programId,
payer: wallet.publicKey,
tokenMetadataProgram: TOKEN_METADATA_PROGRAM_ID,
sysvarInstructions: anchor.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
}
const ix = await createCreateTrifleAccountInstruction(accounts)
return ix;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment