Back to All

Send All Ether

Hi, How do you send all ether from an address without leaving any left. My calculation is as following.
amountToSend = FullAmount - ((gasPrice + maxPriorityFeePerGas) * gasLimit).
But there still remains some small amount of ether left. Like $0.9 . The transaction look as follow:

const transaction = {
to,
value: Number(value).minus(totalGas).toString(),
gasLimit,
gasPrice,
maxPriorityFeePerGas: Number(feeData.maxPriorityFeePerGas),
maxFeePerGas: gasPrice,
nonce,
type: 2,
chainId: 1,
};

ReadMe