Skip to content

Commit 05f238e

Browse files
committed
feat(SOLNENG-27): change to EIP1559 tx type2
1 parent 212e57a commit 05f238e

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

main.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ethereum/go-ethereum/common"
1717
"github.com/ethereum/go-ethereum/core/types"
1818
"github.com/ethereum/go-ethereum/ethclient"
19+
"github.com/ethereum/go-ethereum/rlp"
1920
"github.com/ethereum/go-ethereum/rpc"
2021
"gitlab.com/Blockdaemon/go-tsm-sdkv2/tsm" // Builder Vault MPC SDK for wallet management
2122
"golang.org/x/sync/errgroup"
@@ -57,7 +58,7 @@ func createStakeIntent(stakeApiKey string, stakeRequest *Request) (string, strin
5758
req.Header.Set("Content-Type", "application/json")
5859
req.Header.Set("Accept", "application/json")
5960
req.Header.Set("X-API-Key", stakeApiKey)
60-
//req.Header.Set("Idempotency-Key", "7515F6E2-7A57-4BA5-9CFA-FA7F4ECD41CF")
61+
//req.Header.Set("Idempotency-Key", "45C8C466-6EC6-4C8F-9C88-7B928AFF9A5F")
6162

6263
client := &http.Client{}
6364
resp, err := client.Do(req)
@@ -117,18 +118,21 @@ func craftTx(client *ethclient.Client, ethereumSenderAddress string, contractAdd
117118
log.Fatal(err)
118119
}
119120

120-
unsignedTx := types.NewTx(&types.LegacyTx{
121-
Nonce: nonce,
122-
To: &decodedContactAddress,
123-
Value: totalAmount,
124-
Gas: gasLimit,
125-
GasPrice: gasPrice,
126-
Data: common.FromHex(txData),
121+
unsignedTx := types.NewTx(&types.DynamicFeeTx{
122+
ChainID: chainID,
123+
Nonce: nonce,
124+
To: &decodedContactAddress,
125+
Value: totalAmount,
126+
Gas: gasLimit,
127+
GasTipCap: big.NewInt(2 * 1e9), // 2 Gwei
128+
GasFeeCap: big.NewInt(40 * 1e9), // 40 Gwei
129+
Data: common.FromHex(txData),
127130
})
128131

129-
fmt.Println("\nCrafted unsigned transaction:\n", "Nonce:", unsignedTx.Nonce(), "\n GasPrice:", unsignedTx.GasPrice(), "\n Gas:", unsignedTx.Gas(), "\n To:", unsignedTx.To().String(), "\n Value:", unsignedTx.Value())
132+
fmt.Println("\nCrafted unsigned transaction:\n", "Nonce:", unsignedTx.Nonce(), "\n GasFeeCap:", unsignedTx.GasFeeCap(), "\n Gas:", unsignedTx.Gas(), "\n To:", unsignedTx.To().String(), "\n Value:", unsignedTx.Value())
130133

131-
signer := types.NewEIP155Signer(chainID)
134+
// create a NewLondonSigner for EIP 1559 transactions
135+
signer := types.NewLondonSigner(chainID)
132136

133137
return unsignedTx, signer.Hash(unsignedTx).Bytes(), chainID
134138
}
@@ -197,11 +201,16 @@ func signTx(unsignedTxHash []byte) []byte {
197201
// ! Broadcast stake deposit to chain
198202
func sendTx(client *ethclient.Client, chainID *big.Int, unsignedTx *types.Transaction, sigBytes []byte) string {
199203

200-
signedTx, err := unsignedTx.WithSignature(types.NewEIP155Signer(chainID), sigBytes)
204+
signedTx, err := unsignedTx.WithSignature(types.NewLondonSigner(chainID), sigBytes)
205+
if err != nil {
206+
panic(err)
207+
}
208+
209+
raw, err := rlp.EncodeToBytes(signedTx)
201210
if err != nil {
202211
panic(err)
203212
}
204-
fmt.Println("\nSigned raw transaction:\n", hex.EncodeToString(signedTx.Data()))
213+
fmt.Printf("\nSigned raw transaction: 0x%x", raw)
205214

206215
err = client.SendTransaction(context.Background(), signedTx)
207216
if err != nil {
@@ -258,5 +267,5 @@ func main() {
258267

259268
// ! Broadcast the transaction to the blockchain
260269
txHash := sendTx(client, chainID, unsignedTx, signature)
261-
fmt.Println("\nTransaction hash:", txHash)
270+
fmt.Println("\nBroadcasted transaction hash:", txHash)
262271
}

0 commit comments

Comments
 (0)