From c0cc0492e24cc0ba89a581c724b7ffd9b78b1ae0 Mon Sep 17 00:00:00 2001 From: raviycoder <135521192+raviycoder@users.noreply.github.com> Date: Sun, 21 Jul 2024 12:22:41 +0530 Subject: [PATCH] resolve transaction issue --- scripts/bscOperator.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/bscOperator.js b/scripts/bscOperator.js index cf90330..b464e80 100644 --- a/scripts/bscOperator.js +++ b/scripts/bscOperator.js @@ -335,19 +335,28 @@ try { const provider = getProvider(); const signer = new ethers.Wallet(privateKey, provider); - const limit = await estimateGas({ privateKey, receiver, amount }) + + // 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(); + // Creating and sending the transaction object return signer.sendTransaction({ to: receiver, - value: ethers.utils.parseUnits(amount, "ether"), + value: ethers.utils.parseUnits(amount.toString(), decimals), gasLimit: limit, - nonce: signer.getTransactionCount(), + nonce: await signer.getTransactionCount(), maxPriorityFeePerGas: ethers.utils.parseUnits("2", "gwei"), - }) + }); } catch (e) { - throw new Error(e) + throw new Error(e); } - } + }; + const sendToken = bscOperator.sendToken = async ({ token, privateKey, amount, receiver, contractAddress }) => { // Create a wallet using the private key