Skip to content

Commit

Permalink
fix: metaplex lib
Browse files Browse the repository at this point in the history
  • Loading branch information
CanvasL committed Sep 15, 2024
1 parent a17b411 commit 149d27f
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 44 deletions.
98 changes: 58 additions & 40 deletions extensions/puppet/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import * as anchor from "@coral-xyz/anchor";
import { Keypair, PublicKey } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";
import { Puppet } from "../target/types/puppet";
import { Program } from "@coral-xyz/anchor";
import {
Metaplex,
irysStorage,
keypairIdentity,
} from "@metaplex-foundation/js";
import { Connection, clusterApiUrl } from "@solana/web3.js";
generateSigner,
percentAmount,
createSignerFromKeypair,
signerIdentity,
} from "@metaplex-foundation/umi";
import { createUmi } from '@metaplex-foundation/umi-bundle-defaults'
import {
mplTokenMetadata,
createNft,
fetchDigitalAsset,
} from "@metaplex-foundation/mpl-token-metadata";
import {
getAssociatedTokenAddress,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID,
} from "@solana/spl-token";
import fs from "fs";
import path from "path";

const DEPHY_ID_PROGRAM = new PublicKey(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
);
const DEV_RPC = "https://api.apr.dev";
const DEV_RPC = "https://api.devnet.solana.com";
const SECRET_KEY = fs.readFileSync(
path.join(__dirname, '../keypair.json'),
"utf-8"
)

yargs(hideBin(process.argv))
.command(
Expand All @@ -28,26 +40,29 @@ yargs(hideBin(process.argv))
{
url: { type: "string", demandOption: true },
name: { type: "string", demandOption: true },
privatekey: { type: "string", demandOption: true },
},
async (args) => {
const payer = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(args.privatekey))
);
console.log("pubkey:", payer.publicKey);
const connection = new Connection(clusterApiUrl("devnet"));
const metaplex = Metaplex.make(connection)
.use(keypairIdentity(payer))
.use(irysStorage());
const umi = createUmi(DEV_RPC);

const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(JSON.parse(SECRET_KEY)));

const { nft: collectionNft } = await metaplex.nfts().create({
uri: args.url,
name: args.name,
sellerFeeBasisPoints: 500, // Represents 5.00%.
isCollection: true,
});
console.log(keypair.publicKey)

console.log("mplCollection:", collectionNft.address.toBase58());
const signer = createSignerFromKeypair(umi, keypair);

umi.use(signerIdentity(signer))
umi.use(mplTokenMetadata())
const mint = generateSigner(umi)
await createNft(umi, {
mint,
name: args.name,
uri: args.url,
sellerFeeBasisPoints: percentAmount(5.5),
isCollection: true
}).sendAndConfirm(umi)

const asset = await fetchDigitalAsset(umi, mint.publicKey)
console.log("mplCollection:", asset.mint.publicKey);
}
)
.command(
Expand All @@ -60,27 +75,30 @@ yargs(hideBin(process.argv))
privatekey: { type: "string", demandOption: true },
},
async (args) => {
const payer = Keypair.fromSecretKey(
new Uint8Array(JSON.parse(args.privatekey))
);
const connection = new Connection(clusterApiUrl("devnet"));
const metaplex = Metaplex.make(connection)
.use(keypairIdentity(payer))
.use(irysStorage());
const umi = createUmi(DEV_RPC);

const keypair = umi.eddsa.createKeypairFromSecretKey(new Uint8Array(JSON.parse(SECRET_KEY)));

// Create an NFT under the specified collection.
const { nft } = await metaplex.nfts().create({
uri: args.url,
name: args.name,
sellerFeeBasisPoints: 500, // Represents 5.00%.
collection: new PublicKey(args.collection),
});
const signer = createSignerFromKeypair(umi, keypair);

console.log("mpl_mint:", nft.address.toBase58());
umi.use(signerIdentity(signer))
umi.use(mplTokenMetadata())
const mint = generateSigner(umi)
await createNft(umi, {
mint,
name: args.name,
uri: args.url,
sellerFeeBasisPoints: percentAmount(5.5),
isCollection: true
}).sendAndConfirm(umi)

const asset = await fetchDigitalAsset(umi, mint.publicKey)
console.log("asset:", asset.publicKey)
console.log("mpl_mint:", asset.mint.publicKey);

const mplAta = await getAssociatedTokenAddress(
nft.address, // The mint address of the created NFT
payer.publicKey, // The wallet address of the NFT owner
new anchor.web3.PublicKey(asset.mint.publicKey), // The mint address of the created NFT
new anchor.web3.PublicKey(keypair.publicKey), // The wallet address of the NFT owner
false,
TOKEN_PROGRAM_ID,
ASSOCIATED_TOKEN_PROGRAM_ID
Expand Down
1 change: 1 addition & 0 deletions extensions/puppet/keypair.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[3,98,129,50,166,110,222,238,8,122,218,16,146,91,239,253,219,217,78,248,136,253,20,247,228,232,255,72,51,52,152,232,59,56,47,66,135,204,197,194,83,150,196,82,143,128,67,241,163,111,202,98,165,17,242,25,253,86,24,192,84,74,103,132]
8 changes: 4 additions & 4 deletions extensions/puppet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"test": "ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts",
"cli": "ts-node ./client/index.ts"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
},
"devDependencies": {
"@metaplex-foundation/js": "^0.20.1",
"@coral-xyz/anchor": "^0.30.1",
"@metaplex-foundation/umi": "^0.9.2",
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
"@metaplex-foundation/mpl-token-metadata": "^3.2.1",
"@solana/spl-token": "^0.4.8",
"@solana/web3.js": "^1.95.3",
"@types/bn.js": "^5.1.0",
Expand Down
171 changes: 171 additions & 0 deletions extensions/puppet/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 149d27f

Please sign in to comment.