-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Umi for NFTs, metaplex-foundation/js is deprecated and no longer …
…functional
- Loading branch information
1 parent
242cedc
commit 7fa1424
Showing
9 changed files
with
427 additions
and
665 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// See https://developers.metaplex.com/token-metadata/collections | ||
import { | ||
createNft, | ||
fetchDigitalAsset, | ||
mplTokenMetadata, | ||
} from "@metaplex-foundation/mpl-token-metadata"; | ||
import { | ||
airdropIfRequired, | ||
getExplorerLink, | ||
getKeypairFromFile, | ||
} from "@solana-developers/helpers"; | ||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; | ||
import { | ||
generateSigner, | ||
keypairIdentity, | ||
percentAmount, | ||
} from "@metaplex-foundation/umi"; | ||
import { Connection, LAMPORTS_PER_SOL, clusterApiUrl } from "@solana/web3.js"; | ||
|
||
// create a new connection to the cluster's API | ||
const connection = new Connection(clusterApiUrl("devnet")); | ||
|
||
// initialize a keypair for the user | ||
const user = await getKeypairFromFile(); | ||
|
||
await airdropIfRequired( | ||
connection, | ||
user.publicKey, | ||
1 * LAMPORTS_PER_SOL, | ||
0.1 * LAMPORTS_PER_SOL | ||
); | ||
|
||
console.log("Loaded user:", user.publicKey.toBase58()); | ||
|
||
// Create Umi Instance, using the same endpoint as our connection, | ||
// and using our user to sign transactions | ||
const umi = createUmi(connection.rpcEndpoint); | ||
umi.use(mplTokenMetadata()); | ||
const umiKeypair = umi.eddsa.createKeypairFromSecretKey(user.secretKey); | ||
umi.use(keypairIdentity(umiKeypair)); | ||
|
||
console.log(`Creating collection...`); | ||
// This mint is like a factory for creating NFTs | ||
// Except it only makes one NFT, and it's a collection! | ||
const collectionMint = generateSigner(umi); | ||
const transaction = await createNft(umi, { | ||
mint: collectionMint, | ||
name: "My Collection", | ||
symbol: "MC", | ||
// https://developers.metaplex.com/token-metadata/token-standard#the-non-fungible-standard | ||
uri: "https://raw.githubusercontent.com/solana-developers/professional-education/main/labs/sample-nft-collection-offchain-data.json", | ||
sellerFeeBasisPoints: percentAmount(0), | ||
isCollection: true, | ||
}); | ||
|
||
await transaction.sendAndConfirm(umi); | ||
|
||
const createdCollectionNft = await fetchDigitalAsset( | ||
umi, | ||
collectionMint.publicKey | ||
); | ||
|
||
console.log( | ||
`Created collection 📦! Address is: ${getExplorerLink( | ||
"address", | ||
createdCollectionNft.mint.publicKey, | ||
"devnet" | ||
)}` | ||
); | ||
|
||
console.log("✅ Finished successfully!"); |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.