Skip to content

Instantly share code, notes, and snippets.

@qruz-hq
Created April 24, 2022 21:22
Show Gist options
  • Save qruz-hq/7be9123c41b43f3c324ac124602e166d to your computer and use it in GitHub Desktop.
Save qruz-hq/7be9123c41b43f3c324ac124602e166d to your computer and use it in GitHub Desktop.
Minting function (FrontEnd)
async function mint() {
if (contract) {
showNotification({
id: 'MINT',
message: 'Minting...',
loading: true,
color: 'blue',
autoClose: false,
});
setMinting(true);
const _count = Number(count);
if (publicSale) {
contract.estimateGas
.publicSaleMint(_count, {
value: actualPrice().mul(_count),
})
.then(async (gas: BigNumber) => {
contract
.publicSaleMint(_count, {
value: actualPrice().mul(_count),
gasLimit: Math.floor(gas.toNumber() * 1.4),
})
.then((tx: TransactionResponse) => handleMintResponse(tx))
.catch((e: Error) => handleMintError(e));
});
} else if (preSale) {
contract.estimateGas
.preSaleMint(_count, {
value: actualPrice().mul(_count),
})
.then(async (gas: BigNumber) => {
contract
.preSaleMint(_count, {
value: actualPrice().mul(_count),
gasLimit: Math.floor(gas.toNumber() * 1.4),
})
.then((tx: TransactionResponse) => handleMintResponse(tx))
.catch((e: Error) => handleMintError(e));
});
} else if (!isDAEnded()) {
contract.estimateGas
.dutchAuctionMint(_count, {
value: actualPrice().mul(_count),
})
.then(async (gas: BigNumber) => {
contract
.dutchAuctionMint(_count, {
value: actualPrice().mul(_count),
gasLimit: Math.floor(gas.toNumber() * 1.4),
})
.then((tx: TransactionResponse) => handleMintResponse(tx))
.catch((e: Error) => handleMintError(e));
});
} else {
setMinting(false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment