i want to transfer ALL the ether in my account to the smart contract. I am calculating the gasEstimate and then subtracting it from my total ether balance...but i get an ERROR saying code: -32000, message: 'gas required exceeds allowance (13179)'
const grantorEtherBalance: number = Number(
ethers.utils.formatUnits(await provider.getBalance(grantorAddress), 'ether'),
)
const wallet = new ethers.Wallet(privateKey, provider)
const psigner = wallet.connect(provider)
//send the ether from grantor's wallet to smart contract
const forGasEstimatetx = {
to: '0xa013618172F9E3514843CBF3a45221479A2E4297',
value: ethers.utils.parseEther('0'),
}
const gasEstimate: any = await wallet.estimateGas(forGasEstimatetx)
const sub = feeData * parseInt(gasEstimate)
const sendingEther = grantorEtherBalance - sub
const tx = {
to: '0xa013618172F9E3514843CBF3a45221479A2E4297',
value: ethers.utils.parseEther(sendingEther.toString()),
}
const transaction = await psigner.sendTransaction(tx)
const receipt = await transaction.wait()
console.log('receipt', receipt)```