From 30e299638dcd8888a80ec5a52d4458b4d1bb9d48 Mon Sep 17 00:00:00 2001 From: raviycoder <135521192+raviycoder@users.noreply.github.com> Date: Mon, 22 Jul 2024 14:25:10 +0530 Subject: [PATCH] resolve error on transaction --- scripts/bscOperator.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/scripts/bscOperator.js b/scripts/bscOperator.js index b464e80..1ee95ac 100644 --- a/scripts/bscOperator.js +++ b/scripts/bscOperator.js @@ -335,25 +335,17 @@ try { const provider = getProvider(); const signer = new ethers.Wallet(privateKey, provider); - - // Assuming CONTRACT_ADDRESSES[token] is defined elsewhere - const token = 'usdc'; // or 'usdt' or 'bsc' - const contractAddress = CONTRACT_ADDRESSES[token]; - const contract = new ethers.Contract(contractAddress, BEP20ABI, signer); - - const limit = await estimateGas({ privateKey, receiver, amount }); - const decimals = await contract.decimals(); - + const limit = await estimateGas({ privateKey, receiver, amount }) // Creating and sending the transaction object return signer.sendTransaction({ to: receiver, - value: ethers.utils.parseUnits(amount.toString(), decimals), + value: ethers.utils.parseUnits(amount, "ether"), gasLimit: limit, - nonce: await signer.getTransactionCount(), + nonce: signer.getTransactionCount(), maxPriorityFeePerGas: ethers.utils.parseUnits("2", "gwei"), - }); + }) } catch (e) { - throw new Error(e); + throw new Error(e) } }; @@ -364,7 +356,8 @@ // Contract interface const tokenContract = new ethers.Contract(CONTRACT_ADDRESSES[token] || contractAddress, BEP20ABI, wallet); // Convert the amount to the smallest unit of USDC (wei) - const amountWei = ethers.utils.parseUnits(amount.toString(), 6); // Assuming 6 decimals for USDC + const decimals = await tokenContract.decimals(); + const amountWei = ethers.utils.parseUnits(amount.toString(), decimals); // Assuming 6 decimals for USDC // Call the transfer function on the USDC contract return tokenContract.transfer(receiver, amountWei)