Skip to content

Commit e622e9b

Browse files
committed
chore(SOLNENG-27): docs
1 parent 42d1b7f commit e622e9b

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

main.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/ethereum/go-ethereum/core/types"
1717
"github.com/ethereum/go-ethereum/ethclient"
1818
"github.com/ethereum/go-ethereum/rpc"
19-
"gitlab.com/Blockdaemon/go-tsm-sdkv2/tsm"
19+
"gitlab.com/Blockdaemon/go-tsm-sdkv2/tsm" // Builder Vault MPC SDK for wallet management
2020
"golang.org/x/sync/errgroup"
2121

2222
"github.com/fatih/structs"
@@ -56,7 +56,7 @@ func createStakeIntent(stakeApiKey string, stakeRequest *Request) (string, strin
5656
req.Header.Set("Content-Type", "application/json")
5757
req.Header.Set("Accept", "application/json")
5858
req.Header.Set("X-API-Key", stakeApiKey)
59-
//req.Header.Set("Idempotency-Key", "E96E9CE5-A81E-4178-AAA7-4BDC7ED1BCC2") // ToDo - remove for demos
59+
//req.Header.Set("Idempotency-Key", "E96E9CE5-A81E-4178-AAA7-4BDC7ED1BCC2")
6060

6161
client := &http.Client{}
6262
resp, err := client.Do(req)
@@ -213,42 +213,48 @@ func sendTx(client *ethclient.Client, chainID *big.Int, unsignedTx *types.Transa
213213
func main() {
214214
stakeApiKey := os.Getenv("STAKE_API_KEY")
215215
rpcApiKey := os.Getenv("RPC_API_KEY")
216-
ethereumSenderAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A" // Set your Ethereum sender address here. E.g. "0x71Bff5FFeF6408dAe06c055caB770D76E04831d2"
216+
217+
// Define stake intent parameters
218+
ethereumSenderAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
217219
stakeWithdrawalAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
218220
stakeFeeRecipientAddress := "0xE8fE1C1058b34d5152f2B23908dD8c65715F2D3A"
219221

220-
// Create go-ethereum/rpc client with heaader-based authentication
222+
// Define stake intent request: 1x32ETH
223+
stakeRequest := &Request{
224+
Stakes: []Stake{
225+
{
226+
Amount: "32000000000", // denominated in Gwei
227+
WithdrawalAddress: stakeWithdrawalAddress,
228+
FeeRecipient: stakeFeeRecipientAddress,
229+
},
230+
},
231+
}
232+
233+
// Create go-ethereum/rpc client with header-based authentication
221234
rpcClient, err := rpc.Dial("https://svc.blockdaemon.com/ethereum/holesky/native")
222235
if err != nil {
223236
log.Fatal("Failed to connect to the Ethereum client:", err)
224237
}
225238
rpcClient.SetHeader("X-API-KEY", rpcApiKey)
226239
client := ethclient.NewClient(rpcClient)
227240

228-
// Check balance available for staking
241+
// Check sender wallet balance available for staking
229242
balance, err := client.BalanceAt(context.Background(), common.HexToAddress(ethereumSenderAddress), nil)
230243
if err != nil {
231244
panic(err)
232245
}
233246
fmt.Println("Balance at account:", ethereumSenderAddress, "=", (balance), "wei")
234247

235-
// Define stake intent request: 1x32ETH
236-
stakeRequest := &Request{
237-
Stakes: []Stake{
238-
{
239-
Amount: "32000000000", // denominated in Gwei
240-
WithdrawalAddress: stakeWithdrawalAddress,
241-
FeeRecipient: stakeFeeRecipientAddress,
242-
},
243-
},
244-
}
245-
248+
// Create stake intent nd receive transaction data
246249
txData, contractAddress, totalAmount := createStakeIntent(stakeApiKey, stakeRequest)
247250

251+
// Craft transaction with stake intent unsigned tx data and blockchain inputs
248252
unsignedTx, unsignedTxHash, chainID := craftTx(client, ethereumSenderAddress, contractAddress, totalAmount, txData)
249253

254+
// Sign the transaction with MPC wallet private key shares
250255
signature := signTx(unsignedTxHash)
251256

257+
// Broadcast the transaction to the blockchain
252258
txHash := sendTx(client, chainID, unsignedTx, signature)
253259
fmt.Println("\nTransaction hash:", txHash)
254260
}

0 commit comments

Comments
 (0)