From 595d723672b3ec0220ca4e4c4fcbc4ce0eaf8048 Mon Sep 17 00:00:00 2001 From: MarkSackerberg <93528482+MarkSackerberg@users.noreply.github.com> Date: Mon, 23 Dec 2024 22:52:03 +0100 Subject: [PATCH 1/2] extend scripts with boilerplate --- .../create-your-first-hybrid-collection.md | 140 +++++++++++++----- 1 file changed, 107 insertions(+), 33 deletions(-) diff --git a/src/pages/mpl-hybrid/guides/create-your-first-hybrid-collection.md b/src/pages/mpl-hybrid/guides/create-your-first-hybrid-collection.md index 1435ff3e..515ae43a 100644 --- a/src/pages/mpl-hybrid/guides/create-your-first-hybrid-collection.md +++ b/src/pages/mpl-hybrid/guides/create-your-first-hybrid-collection.md @@ -248,20 +248,49 @@ console.log(`Escrow created! https://explorer.solana.com/tx/${signature}?cluster {% totem-accordion title="Send Assets to the Escrow" %} ```javascript -import { transfer } from '@metaplex-foundation/mpl-core' +import { keypairIdentity, publicKey } from "@metaplex-foundation/umi"; +import { + MPL_HYBRID_PROGRAM_ID, + mplHybrid, +} from "@metaplex-foundation/mpl-hybrid"; +import { readFileSync } from "fs"; +import { mplTokenMetadata } from "@metaplex-foundation/mpl-token-metadata"; +import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; +import { + string, + publicKey as publicKeySerializer, +} from "@metaplex-foundation/umi/serializers"; +import { transfer } from "@metaplex-foundation/mpl-core"; -// Derive the Escrow -const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [ - string({ size: 'variable' }).serialize('escrow'), - publicKeySerializer().serialize(collection), -])[0]; +(async () => { + const collection = publicKey(""); // The collection we are swapping to/from + const asset = publicKey(""); // Mint Address of the NFT you want to send + + const umi = createUmi("").use(mplHybrid()).use(mplTokenMetadata()); + + const wallet = ""; // The path to your filesystem Wallet + const secretKey = JSON.parse(readFileSync(wallet, "utf-8")); + + // Create a keypair from your private key + const keypair = umi.eddsa.createKeypairFromSecretKey( + new Uint8Array(secretKey) + ); + umi.use(keypairIdentity(keypair)); + + // Derive the Escrow + const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [ + string({ size: "variable" }).serialize("escrow"), + publicKeySerializer().serialize(collection), + ])[0]; + + // Transfer Asset to it + const transferAssetTx = await transfer(umi, { + asset, + collection, + newOwner: escrow, + }).sendAndConfirm(umi); +})(); -// Transfer Asset to it -const transferAssetTx = await transfer(umi, { - asset, - collection, - newOwner: escrow -}).sendAndConfirm(umi); ``` {% /totem-accordion %} @@ -269,28 +298,73 @@ const transferAssetTx = await transfer(umi, { {% totem-accordion title="Send Fungible Tokens to the Escrow" %} ```javascript -import { transactionBuilder } from '@metaplex-foundation/umi' -import { createTokenIfMissing, transferTokens } from '@metaplex-foundation/mpl-toolbox' +import { + keypairIdentity, + publicKey, + transactionBuilder, +} from "@metaplex-foundation/umi"; +import { + createTokenIfMissing, + findAssociatedTokenPda, + transferTokens, +} from "@metaplex-foundation/mpl-toolbox"; +import { + MPL_HYBRID_PROGRAM_ID, + mplHybrid, +} from "@metaplex-foundation/mpl-hybrid"; +import { readFileSync } from "fs"; +import { mplTokenMetadata } from "@metaplex-foundation/mpl-token-metadata"; +import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; +import { + string, + publicKey as publicKeySerializer, +} from "@metaplex-foundation/umi/serializers"; + +(async () => { + const collection = publicKey(""); // The collection we are swapping to/from + const token = publicKey(""); // The token we are swapping to/from + + const umi = createUmi("").use(mplHybrid()).use(mplTokenMetadata()); + + const wallet = ""; // The path to your filesystem Wallet + const secretKey = JSON.parse(readFileSync(wallet, "utf-8")); + + // Create a keypair from your private key + const keypair = umi.eddsa.createKeypairFromSecretKey( + new Uint8Array(secretKey) + ); + umi.use(keypairIdentity(keypair)); + + // Derive the Escrow + const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [ + string({ size: "variable" }).serialize("escrow"), + publicKeySerializer().serialize(collection), + ])[0]; + + // Transfer Fungible Tokens to it (after creating the ATA if needed) + const transferTokenTx = await transactionBuilder() + .add( + createTokenIfMissing(umi, { + mint: token, + owner: escrow, + }) + ) + .add( + transferTokens(umi, { + source: findAssociatedTokenPda(umi, { + mint: token, + owner: umi.identity.publicKey, + }), + destination: findAssociatedTokenPda(umi, { + mint: token, + owner: escrow, + }), + amount: 300000000, + }) + ) + .sendAndConfirm(umi); +})(); -// Derive the Escrow -const escrow = umi.eddsa.findPda(MPL_HYBRID_PROGRAM_ID, [ - string({ size: 'variable' }).serialize('escrow'), - publicKeySerializer().serialize(collection), -])[0]; - -// Transfer Fungible Tokens to it (after creating the ATA if needed) -const transferTokenTx = await transactionBuilder().add( - createTokenIfMissing(umi, { - mint: token, - owner: escrow - }) -).add( - transferTokens(umi, { - source: findAssociatedTokenPda(umi, { mint: token, owner: umi.identity.publicKey }), - destination: findAssociatedTokenPda(umi, { mint: token, owner: escrow }), - amount, - }) -).sendAndConfirm(umi) ``` {% /totem-accordion %} From 35ce6669aa518b2eeb940efcf30a5848352cde3f Mon Sep 17 00:00:00 2001 From: MarkSackerberg <93528482+MarkSackerberg@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:36:17 +0100 Subject: [PATCH 2/2] add overall section --- src/components/products/guides/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/components/products/guides/index.js b/src/components/products/guides/index.js index 74ef8f50..858d68eb 100644 --- a/src/components/products/guides/index.js +++ b/src/components/products/guides/index.js @@ -183,6 +183,12 @@ export const guides = { created: '2024-09-20', updated: null, // null means it's never been updated }, + { + title: 'MPL-Hybrid / MPL-404', + href: '/mpl-hybrid/guides', + created: '2025-01-06', + updated: null, // null means it's never been updated + }, ], }, {