-1

I'm trying to sign and broadcast ETH transaction, but it seems like I'm struggling to calculate the correct fee. Here's sample data I use to sign a transaction:

maxPriorityFeePerGas: 0x1
maxFeePerGas: 0xe0c1e0193ba0
gasLimit: 0x5208
to: 0x........................................
value: 0x17fd5b2c13bf40
data: 0x

Balance of the wallet: 0.006999615780748 ETH

If my calculation (and understanding) is correct, I should not pay more than 247123293060000 wei for the transaction (maxFeePerGas). The amount I'm trying to send is 6999615780748000 (value). Both together make 6999615800000000 wei (0.006999615780748 ETH) - the exact balance of my wallet. So, at least in theory, I should have enough to pay the transaction. And yet, when I try to broadcast it to the RPC it returns "insufficient funds for gas * price + value".

I've been playing with the fees and amount I send for ~a week now. Another error I've seen quite a few times is "tx fee (7.29 ether) exceeds the configured cap (1.00 ether)". This is what makes me believe my calculation is wrong. I'm passing all parameters as wei. Maybe this is where things go wrong?

It would be great if someone can find the mistake here. Many thanks in advance.

  • Have you tried dropping the amount you are transferring so that it is much smaller than the amount you have in the wallet? <50%? – Jeremy Savage Oct 07 '22 at 22:54

1 Answers1

0

I have also got the same issue when I was trying to add manual gas values in my unsigned transaction, I will suggest you can use ethers.js for calculating these value, please look into the below code:

    const provider = new ethers.providers.JsonRpcProvider(network.networkURL)
    const gasFeeData = await provider.getFeeData();
    const nonce = await provider.getTransactionCount(senderAddress);
    const chainId = (await provider.getNetwork()).chainId;
    const rawTxn: any = {
        to: "0x....",
        maxFeePerGas: gasFeeData.maxFeePerGas,
        maxPriorityFeePerGas: gasFeeData.maxPriorityFeePerGas,
        chainId: chainId,
        data: null,
        gasPrice: null,
        nonce: nonce,
        value: 0x17fd5b2c13bf40,
        from: senderAddress,
        type: 2
    }
    rawTxn["gasLimit"] = await provider.estimateGas(rawTxn)
    delete rawTxn["from"]

    const unsignedTxn = await ethers.utils.resolveProperties(rawTxn);

Now you sign your unsignedTxn and send it to the blockchain.