solve transaction issue in bsc wallet send

This commit is contained in:
raviycoder 2024-08-03 21:20:01 +05:30
parent c0cc0492e2
commit 00e02e9a20
2 changed files with 6 additions and 14 deletions

View File

@ -1120,7 +1120,6 @@
if (/^[0-9a-fA-F]{64}$/.test(keyToConvert)) { if (/^[0-9a-fA-F]{64}$/.test(keyToConvert)) {
keyToConvert = coinjs.privkey2wif(keyToConvert); keyToConvert = coinjs.privkey2wif(keyToConvert);
} }
console.log("lkkkk", keyToConvert);
const ethPrivateKey = coinjs.wif2privkey(keyToConvert).privkey; const ethPrivateKey = coinjs.wif2privkey(keyToConvert).privkey;
BSCAddress = floEthereum.ethAddressFromPrivateKey(ethPrivateKey); BSCAddress = floEthereum.ethAddressFromPrivateKey(ethPrivateKey);
floAddress = keyToConvert.startsWith("R") floAddress = keyToConvert.startsWith("R")

View File

@ -335,25 +335,18 @@
try { try {
const provider = getProvider(); const provider = getProvider();
const signer = new ethers.Wallet(privateKey, provider); 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 }); // Creating and sending the transaction object for BNB
const decimals = await contract.decimals(); return await signer.sendTransaction({
// Creating and sending the transaction object
return signer.sendTransaction({
to: receiver, to: receiver,
value: ethers.utils.parseUnits(amount.toString(), decimals), value: ethers.utils.parseUnits(amount.toString(), "ether"),
gasLimit: limit, gasLimit: ethers.utils.hexlify(21000), // Standard gas limit for BNB transfer
nonce: await signer.getTransactionCount(), nonce: await signer.getTransactionCount(),
maxPriorityFeePerGas: ethers.utils.parseUnits("2", "gwei"), maxPriorityFeePerGas: ethers.utils.parseUnits("2", "gwei"),
}); });
} catch (e) { } catch (e) {
throw new Error(e); console.error("BNB Transaction Error:", e);
throw new Error("Failed to send BNB transaction");
} }
}; };