umbracle / ethgo

Ethereum Golang API
https://www.ethgoproject.io
Mozilla Public License 2.0
484 stars 134 forks source link

How to send EIP1559 transction? #187

Closed dingding001 closed 2 years ago

dingding001 commented 2 years ago

Type:0 is OK, Type:2 error

According to structs_marshal_rlp.go:MarshalRLPWith function

I add: Type, ChainID,MaxPriorityFeePerGas,MaxFeePerGas, delete GasPrice,

result: {"code":-32000,"message":"invalid sender"}

//---------test---------------------------

web3 "github.com/umbracle/ethgo"

txn := &web3.Transaction{ To: &conAddr, Value:big.NewInt(0), //GasPrice: gasPrice, Gas:90000, Nonce:nonce, Input:data, Type:web3.TransactionDynamicFee, //2 ChainID: new(big.Int).SetInt64(137), // MaxPriorityFeePerGas:new(big.Int).SetInt64(35000000000), // 35Gwei MaxFeePerGas: new(big.Int).SetInt64(100000000000)} // 100Gwei

signer := wallet.NewEIP155Signer(137)
txn, _ = signer.SignTx(txn, key)

//LogStruct(&txn)
//sendData := txn.MarshalRLP()
sendData,err := txn.MarshalRLPTo(nil)
if(err != nil){
    fmt.Println(err)
    return
}

hash, err := Client.Eth().SendRawTransaction(sendData)
if(err != nil){
    fmt.Println(err)
    return
}
fmt.Println(hash)
ferranbt commented 2 years ago

Initial approach in #198