const mintTokenTxn = new TokenMintTransaction()
.setTokenId(tokenId)
.setMetadata(metadatas)
.freezeWith(client);
const mintTokenTxnSigned = await mintTokenTxn.sign(supplyKey);
// submit txn to hedera network
const txnResponse = await mintTokenTxnSigned.execute(client);
const mintTokenRx = await txnResponse.getReceipt(client);
const mintTokenStatus = mintTokenRx.status.toString();
console.log(`Token mint was a ${mintTokenStatus}`);
};
export const createNewNftCollection = async (
client: Client,
tokenName: string,
tokenSymbol: string,
metadataIPFSUrls: Buffer[], // already uploaded ipfs metadata json files
treasuryAccountId: string | AccountId,
treasuryAccountPrivateKey: PrivateKey,
): Promise<{
tokenId: TokenId,
supplyKey: PrivateKey,
}> => {
// generate supply key
const supplyKey = PrivateKey.generateECDSA();
const [tokenId,] = await createNonFungibleToken(client, treasuryAccountId, supplyKey, treasuryAccountPrivateKey, 0, tokenName, tokenSymbol);
if (tokenId === null || tokenId === undefined) {
throw new Error("Somehow tokenId is null");
}
const metadatas: Uint8Array[] = metadataIPFSUrls.map(url => Buffer.from(url));
// mint token
await mintToken(client, tokenId, metadatas, supplyKey);
return {
tokenId: tokenId,
supplyKey: supplyKey,
};
}