/
mint-id.ts
39 lines (32 loc) · 1.17 KB
/
mint-id.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { NextApiRequest, NextApiResponse } from 'next';
import { Contract } from 'ethers';
import { config } from '../../../config';
import TalentLayerID from '../../../contracts/ABI/TalentLayerID.json';
import { getDelegationSigner } from '../utils/delegate';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { handle, handlePrice, userAddress } = req.body;
// @dev : you can add here all the checks you need to confirm the delegation for a user
try {
if (process.env.NEXT_PUBLIC_ACTIVE_DELEGATE_MINT !== 'true') {
res.status(500).json('Delegation is not activated');
return null;
}
const signer = await getDelegationSigner(res);
if (!signer) {
return;
}
const talentLayerID = new Contract(config.contracts.talentLayerId, TalentLayerID.abi, signer);
const transaction = await talentLayerID.mintForAddress(
userAddress,
process.env.NEXT_PUBLIC_PLATFORM_ID,
handle,
{
value: handlePrice,
},
);
res.status(200).json({ transaction: transaction });
} catch (error) {
console.log('errorDebug', error);
res.status(500).json({ error: error });
}
}