How to properly sign an Ethereum transaction?

712 views Asked by At

I'm learning Ethereum on GOlang. I work through Ganache GUI. I'm trying to make a transfer from 1 wallet to another, but I get an error at the stage of sending a transaction through the client. I think the problem is in the config where I sign the transaction. Tell me what config is needed for my transaction?

    tx := types.NewTx(&types.DynamicFeeTx{
    Nonce:     nonce,
    GasTipCap: gasTipCap,
    GasFeeCap: gasFeeCap,
    Gas:       gas,
    To:        &toAdress,
    Value:     value,
    Data:      data})

config, block := params.TestChainConfig, params.TestChainConfig.MuirGlacierBlock

signer := types.MakeSigner(config, block)

signedTx, err := types.SignTx(tx, signer, privateKey)
if err != nil {
    log.Fatal("Unable to sign TX")
}

if err != nil {
    log.Fatal("Unable to cast to raw txn")
}

err = client.SendTransaction(context.Background(), signedTx)

if err != nil {
    log.Fatal("Unable to submit transaction")
}

fmt.Printf("tx sent: %s", signedTx.Hash().Hex())
0

There are 0 answers