How to implement batch nft minting transactions? #362
Unanswered
JohnVersus
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi @JohnVersus , in case you're still struggling with this, I had the same requirement in my project and below is a rough sketch of how I implemented it. My project is still on version 0.16.1 of the SDK, I think the syntax may have changed a little since then: import {Metaplex, walletAdapterIdentity} from "@metaplex-foundation/js";
import {clusterApiUrl, Keypair} from "@solana/web3.js";
const BATCH_SIZE = 10
const metaplex = new Metaplex(new Connection(clusterApiUrl('devnet')))
const sourceArray = []
for (let i = 0; i < BATCH_SIZE; i++) {
sourceArray.push(i)
}
const updateAuthority = Keypair.generate()
const recentBlockhash = await metaplex.rpc().getLatestBlockhash()
const txs = await Promise.all(sourceArray.map(async i => {
const useNewMint = Keypair.generate()
const tx = (await metaplex
.use(walletAdapterIdentity(wallet))
.nfts()
.builders()
.create({
useNewMint,
updateAuthority,
uri: 'http://example.com/mynft',
sellerFeeBasisPoints: 1000,
name: `NFT #${i}`
})).toTransaction()
tx.recentBlockhash = recentBlockhash
tx.partialSign(useNewMint, updateAuthority)
return tx
}))
const signedTxs = await wallet.signAllTransactions(txs)
const hashes = await Promise.all(signedTxs.map(tx => metaplex.connection.sendRawTransaction(tx)))
await Promise.all(hashes.map(h => metaplex.rpc().confirmTransaction(h))) PS: I haven't actually run this code, there might be an error or another, but roughly speaking this is what worked for me. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi @lorisleiva ,
My question is related to issue #19. Is there an example of how to use this with Metaplex transactions?
I want to batch mint nft's using
metaplex.nfts().create
without having to sign multiple transactions. Is it possible to achieve this by usingsignAllTransactions
or through any other way?Beta Was this translation helpful? Give feedback.
All reactions