How mintForAddress works
In this section, we will provide a detailed explanation of how the mintForAddress function works, which allows users to mint their TalentLayerID without paying any fees.
1 - The Front End
const onSubmit = async (
submittedValues: IFormValues,
{ setSubmitting }: { setSubmitting: (isSubmitting: boolean) => void },
) => {
if (account && account.address && account.isConnected && provider && signer) {
try {
const contract = new ethers.Contract(
config.contracts.talentLayerId,
TalentLayerID.abi,
signer,
);
const handlePrice = await contract.getHandlePrice(submittedValues.handle);
console.log(process.env.NEXT_PUBLIC_ACTIVE_DELEGATE_MINT);
if (process.env.NEXT_PUBLIC_ACTIVE_DELEGATE_MINT === 'true') {
const response = await delegateMintID(
submittedValues.handle,
handlePrice,
account.address,
);
tx = response.data.transaction;
} else {
tx = await contract.mint(process.env.NEXT_PUBLIC_PLATFORM_ID, submittedValues.handle, {
value: handlePrice,
});
}
await createTalentLayerIdTransactionToast(
{
pending: 'Minting your Talent Layer Id...',
success: 'Congrats! Your Talent Layer Id is minted',
error: 'An error occurred while creating your Talent Layer Id',
},
provider,
tx,
account.address,
);
setSubmitting(false);
// TODO: add a refresh function on TL context and call it here rather than hard refresh
router.reload();
} catch (error: any) {
showErrorTransactionToast(error);
}
} else {
openConnectModal();
}
};See the Full Code Implemented on Our Demo DAPP
Last updated