This is an example demonstrating how to use the Allbridge Core SDK to check the allowance and create an approval.
if (
// check if tokens already approved
await sdk.bridge.checkAllowance({
token: sourceTokenInfo,
owner: fromAddress,
gasFeePaymentMethod: gasFeePaymentMethod,
amount: totalAmountFloat,
})
) {
console.log("The granted allowance is enough for the transaction");
} else {
console.log("The granted allowance is NOT enough for the transaction");
}
To make approve transaction
// authorize the bridge to transfer tokens from the sender's address
const rawTransactionApprove = await sdk.bridge.rawTxBuilder.approve({
token: sourceTokenInfo,
owner: fromAddress,
});
const approveTxReceipt = await sendRawTransaction(rawTransactionApprove as as RawEvmTransaction);
console.log("approve tx id:", approveTxReceipt.transactionHash);