Generating the coupons
We've already got most of the work done for this in our coupons.js file that we created earlier and used in our tests.
Let's create a new script called generateCoupons.js in our scripts folder and fill it with the following code:
const { createCoupon } = require("./coupons");
const fs = require('fs');
require("dotenv").config();
// 1. Insert private key corresponding to _couponSigner
const privateKey = process.env.PRIVATE_KEY;
// 2. Populate with addresses to whitelist
let mint = [
// Put all wallets that should be on the "mint" whitelist
];
let claim = [
// put all wallets that should beon the "claim" whitelist
];
// 3. run `node scripts/generateCoupons.js
// 4. Signatures will be saved as coupons.json
const main = async () => {
let output = [];
console.log('Generating...');
for (let i = 0; i < mint.length; i++) {
let signature = await createCoupon(mint[i], 0, privateKey);
output.push({
wallet: mint[i],
type: 'mint',
r: signature.r,
s: signature.s,
v: signature.v
})
}
for (let i = 0; i < claim.length; i++) {
let signature = await createCoupon(claim[i], 1, privateKey);
output.push({
wallet: claim[i],
type: 'claim',
r: signature.r,
s: signature.s,
v: signature.v
})
}
let data = JSON.stringify(output);
fs.writeFileSync('coupons.json', data);
console.log('Done.');
console.log('Check the coupons.json file.');
};
const runMain = async () => {
try {
await main();
process.exit(0);
} catch (error) {
console.log(error);
process.exit(1);
}
};
runMain();
You'll need to populate the mint and claim arrays with your list of wallets, and then run node run scripts/generateCoupons.js. This will generate your coupons and save them to a coupons.json file in a format that is convenient for serving behing a "coupons API" - which we'll cover below.