Go-Ethereum – How to Create and Sign EIP1559 Transaction with Go

eip-1559go-ethereumraw-transactiontransactions

i am kinda new to golang and i would appreciate any help.

My main purpose is offline signing EIP1559 transactions based on a json using go-ethereum. I have managed to sign legacy transactions following docs and got success on eth transfers but my erc20 transactions were reverted.
I have used types.NewTransaction() method and saw that it was deprecated.

I have been digging around the web to find some examples of the new EIP1559 transaction creation using types.NewTx() but i have been unsuccessful.

Best Answer

I have managed to create and sign transactions:

tx := types.NewTx(&types.DynamicFeeTx{
    ChainID: chainID,
    Nonce: nonce,
    GasFeeCap: feeCap,
    GasTipCap: tip,
    Gas: gas,
    To: &toAddress,
    Value: value,
    Data: txData,
})