@@ -16,6 +16,7 @@ import (
16
16
"github.com/ethereum/go-ethereum/common"
17
17
"github.com/ethereum/go-ethereum/core/types"
18
18
"github.com/ethereum/go-ethereum/ethclient"
19
+ "github.com/ethereum/go-ethereum/rlp"
19
20
"github.com/ethereum/go-ethereum/rpc"
20
21
"gitlab.com/Blockdaemon/go-tsm-sdkv2/tsm" // Builder Vault MPC SDK for wallet management
21
22
"golang.org/x/sync/errgroup"
@@ -57,7 +58,7 @@ func createStakeIntent(stakeApiKey string, stakeRequest *Request) (string, strin
57
58
req .Header .Set ("Content-Type" , "application/json" )
58
59
req .Header .Set ("Accept" , "application/json" )
59
60
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 ")
61
62
62
63
client := & http.Client {}
63
64
resp , err := client .Do (req )
@@ -117,18 +118,21 @@ func craftTx(client *ethclient.Client, ethereumSenderAddress string, contractAdd
117
118
log .Fatal (err )
118
119
}
119
120
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 ),
127
130
})
128
131
129
- fmt .Println ("\n Crafted 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 ("\n Crafted unsigned transaction:\n " , "Nonce:" , unsignedTx .Nonce (), "\n GasFeeCap :" , unsignedTx .GasFeeCap (), "\n Gas:" , unsignedTx .Gas (), "\n To:" , unsignedTx .To ().String (), "\n Value:" , unsignedTx .Value ())
130
133
131
- signer := types .NewEIP155Signer (chainID )
134
+ // create a NewLondonSigner for EIP 1559 transactions
135
+ signer := types .NewLondonSigner (chainID )
132
136
133
137
return unsignedTx , signer .Hash (unsignedTx ).Bytes (), chainID
134
138
}
@@ -197,11 +201,16 @@ func signTx(unsignedTxHash []byte) []byte {
197
201
// ! Broadcast stake deposit to chain
198
202
func sendTx (client * ethclient.Client , chainID * big.Int , unsignedTx * types.Transaction , sigBytes []byte ) string {
199
203
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 )
201
210
if err != nil {
202
211
panic (err )
203
212
}
204
- fmt .Println ("\n Signed raw transaction:\n " , hex . EncodeToString ( signedTx . Data ()) )
213
+ fmt .Printf ("\n Signed raw transaction: 0x%x " , raw )
205
214
206
215
err = client .SendTransaction (context .Background (), signedTx )
207
216
if err != nil {
@@ -258,5 +267,5 @@ func main() {
258
267
259
268
// ! Broadcast the transaction to the blockchain
260
269
txHash := sendTx (client , chainID , unsignedTx , signature )
261
- fmt .Println ("\n Transaction hash:" , txHash )
270
+ fmt .Println ("\n Broadcasted transaction hash:" , txHash )
262
271
}
0 commit comments