Copy import {
createClient,
createAccountEthers5,
createPublicProviderEthers5,
isBlindMintProduct,
isEditionProduct,
} from '@manifoldxyz/client-sdk';
import { ethers } from 'ethers';
// Setup provider for the network
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL!);
const networkId = Number(process.env.NETWORK_ID!); // e.g., 1 for mainnet, 8453 for Base
// Create public provider for the client
const publicProvider = createPublicProviderEthers5({
[networkId]: provider
});
// Initialize the client
const client = createClient({ publicProvider });
const product = await client.getProduct('INSTANCE_ID');
// Check product status first
const productStatus = await product.getStatus();
if (productStatus !== 'active') {
throw new Error(`Product is ${productStatus}`);
}
// Handle different product types
if (!isEditionProduct(product)) {
throw new Error('Unsupported product type');
}
// Setup wallet for signing transactions
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY!, provider);
const account = createAccountEthers5({ wallet });
try {
const prepared = await product.preparePurchase({
recipientAddress: wallet.address,
payload: { quantity: 1 },
});
const order = await product.purchase({
account,
preparedPurchase: prepared,
});
console.log(
order.status,
order.receipts.map((r) => r.txHash),
);
} catch (error) {
console.log(`Unable to execute transaction: ${(error as Error).message}`);
}