Skip to main content

Cancel a mint voucher

Due to the design of the mint voucher, the platform only allows one pending voucher at a time for a given buyer and a given contract. The buyer could only obtain a new one if the existing voucher is redeemed, expired or cancelled. In this case, you may want to proactively cancel a pending voucher.

To cancel the pending mint voucher, you need to call the token contract with the voucher nonce. You will need a library that connects with a Web3Provider, such as ethers.js or wagmi.sh. You will also need the contract address, the mint voucher abi, and the function name you want to call, in this case, is cancelVoucher.

const { config, isLoading } = usePrepareContractWrite({
address: voucherData.contract,
abi: MintVoucherABI,
functionName: 'cancelVoucher',
chainId: voucherData.network_id,
args: [voucherData.voucher.nonce],
onError: err => {
handlePrepareError(err);
},
});
const { write, writeAsync, isLoading, isSuccess } = useContractWrite({
...config,
onSuccess(data) {
...
},
onError: (err) => {
handlePrepareError(err);
},
});
const handleCancel = async () => {
if (writeAsync) {
try {
const tx = await writeAsync();
const txReceipt = await tx.wait();
if (txReceipt.status === 1) {
...
} else {
setTxError(true);
}
} catch (err) {
handleTxError(err);
setTxError(true);
}
}
};

Alternatively, you can do so via Etherscan or Polygonscan. Find the token contract by entering the contract address. If the contract has been verified, the Write Contract feature allows the buyer to connect they wallet address used for the voucher and directly cancel the voucher on-chain.