Create a collection

The following code shows how to use the HandCash Minter to inscribe a collection on-chain.

import { HandCashMinter } from "@handcash/handcash-connect";

const handCashMinter = HandCashMinter.fromAppCredentials({
  appId: 'your-app-id',
  authToken: 'your-business-wallet-auth-token',
});

const jsonData = fs.readFileSync('./assets/dummy/collectionInfo.json', 'utf8');
const collectionDefinition = await handCashMinter.loadItemsFromJson(jsonData);

console.log(`⏳ Creating mint order of type collection...`);
let order = await handCashMinter.createCollectionOrder(collectionDefinition.collection);
console.log(`- ✅ Mint order created. Order ID: ${order.id}`);
order = await handCashMinter.commitOrder(order.id);
console.log('- ✅ Mint order committed');

console.log(`- ⏳ Paying ${order.payment.amountInUSD} USD to inscribe the collection on-chain...`);
const paymentResult = await handCashMinter.payPaymentRequest(order.payment.paymentRequestId);
console.log(`- ✅ Order paid. TransactionId: ${paymentResult.transactionId}`);

console.log(`- ⏳ Inscribing collection...`);
while (order.pendingInscriptions > 0) {
  console.log(`- ⏳ Inscribing items. ${order.pendingInscriptions} pending inscriptions...`);
  order = await handCashMinter.inscribeNextBatch(order.id);
}
const items = await handCashMinter.getOrderItems(order.id);
console.log(`- ✅ Collection inscribed. Use the collectionId: ${items[0].id} to inscribe the collection items`);