Skip to content

Commit

Permalink
resolve error on transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
raviycoder committed Jul 22, 2024
1 parent c0cc049 commit 30e2996
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions scripts/bscOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};

Expand All @@ -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)
Expand Down

0 comments on commit 30e2996

Please sign in to comment.