@@ -3,6 +3,7 @@ package main
33import (
44 "bytes"
55 "context"
6+ "encoding/hex"
67 "encoding/json"
78 "fmt"
89 "log"
@@ -50,13 +51,13 @@ type Response struct {
5051func createStakeIntent (stakeApiKey string , stakeRequest * Request ) (string , string , * big.Int ) {
5152 requestJson , _ := json .Marshal (stakeRequest )
5253
53- fmt .Println ("\n Stake request:\n " , structs .Map (stakeRequest ))
54+ fmt .Println ("\n Stake API request:\n " , structs .Map (stakeRequest ))
5455
5556 req , _ := http .NewRequest ("POST" , "https://svc.blockdaemon.com/boss/v1/ethereum/holesky/stake-intents" , bytes .NewBuffer (requestJson ))
5657 req .Header .Set ("Content-Type" , "application/json" )
5758 req .Header .Set ("Accept" , "application/json" )
5859 req .Header .Set ("X-API-Key" , stakeApiKey )
59- //req.Header.Set("Idempotency-Key", "E96E9CE5-A81E-4178-AAA7-4BDC7ED1BCC2 ")
60+ //req.Header.Set("Idempotency-Key", "7515F6E2-7A57-4BA5-9CFA-FA7F4ECD41CF ")
6061
6162 client := & http.Client {}
6263 resp , err := client .Do (req )
@@ -79,7 +80,7 @@ func createStakeIntent(stakeApiKey string, stakeRequest *Request) (string, strin
7980 amount = amount .Mul (amount , new (big.Int ).SetInt64 (1000000000 ))
8081 totalAmount .Add (totalAmount , amount )
8182 }
82- fmt .Println ("\n Stake response:\n " , structs .Map (stakeResponse ))
83+ fmt .Println ("\n Stake API response:\n " , structs .Map (stakeResponse ))
8384
8485 return stakeResponse .Ethereum .UnsignedTransaction , stakeResponse .Ethereum .ContractAddress , totalAmount
8586}
@@ -182,13 +183,13 @@ func signTx(unsignedTxHash []byte) []byte {
182183 panic (err )
183184 }
184185
185- // Construct Ethereum V R S signature format
186+ // Construct Ethereum R S V signature format
186187
187188 sigBytes := make ([]byte , 2 * 32 + 1 )
188189 copy (sigBytes [0 :32 ], signature .R ())
189190 copy (sigBytes [32 :64 ], signature .S ())
190191 sigBytes [64 ] = byte (signature .RecoveryID ())
191- fmt .Println ("\n Transaction signature:\n " , sigBytes )
192+ fmt .Println ("\n Transaction signature:\n " , hex . EncodeToString ( sigBytes ) )
192193
193194 return sigBytes
194195}
@@ -200,7 +201,7 @@ func sendTx(client *ethclient.Client, chainID *big.Int, unsignedTx *types.Transa
200201 if err != nil {
201202 panic (err )
202203 }
203- fmt .Println ("\n Signed raw transaction:\n " , signedTx .Data ())
204+ fmt .Println ("\n Signed raw transaction:\n " , hex . EncodeToString ( signedTx .Data () ))
204205
205206 err = client .SendTransaction (context .Background (), signedTx )
206207 if err != nil {
@@ -214,7 +215,7 @@ func main() {
214215 stakeApiKey := os .Getenv ("STAKE_API_KEY" )
215216 rpcApiKey := os .Getenv ("RPC_API_KEY" )
216217
217- // Define stake intent parameters
218+ // ! Define stake intent parameters
218219 ethereumSenderAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
219220 stakeWithdrawalAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
220221 stakeFeeRecipientAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
@@ -245,16 +246,16 @@ func main() {
245246 }
246247 fmt .Println ("Balance at account:" , ethereumSenderAddress , "=" , (balance ), "wei" )
247248
248- // Create stake intent nd receive transaction data
249+ // ! Create stake intent and receive transaction data
249250 txData , contractAddress , totalAmount := createStakeIntent (stakeApiKey , stakeRequest )
250251
251- // Craft transaction with stake intent unsigned tx data and blockchain inputs
252+ // ! Craft transaction with stake intent unsigned tx data and blockchain inputs
252253 unsignedTx , unsignedTxHash , chainID := craftTx (client , ethereumSenderAddress , contractAddress , totalAmount , txData )
253254
254- // Sign the transaction with MPC wallet private key shares
255+ // ! Sign the transaction with MPC wallet private key shares
255256 signature := signTx (unsignedTxHash )
256257
257- // Broadcast the transaction to the blockchain
258+ // ! Broadcast the transaction to the blockchain
258259 txHash := sendTx (client , chainID , unsignedTx , signature )
259260 fmt .Println ("\n Transaction hash:" , txHash )
260261}
0 commit comments