-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
68 lines (57 loc) · 1.94 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* This example code demonstrates creating an Ethereum Partial ETH (<32 ETH) workflow, the fundamental process handler for an E2E staking experience.
*/
package main
import (
"context"
"log"
"github.com/coinbase/staking-client-library-go/auth"
"github.com/coinbase/staking-client-library-go/client"
"github.com/coinbase/staking-client-library-go/client/options"
api "github.com/coinbase/staking-client-library-go/gen/go/coinbase/staking/orchestration/v1"
"google.golang.org/protobuf/encoding/protojson"
)
var (
apiKeyName = "your-api-key-name"
apiPrivateKey = "your-api-private-key"
)
func main() {
ctx := context.Background()
// Loads the API key.
apiKey, err := auth.NewAPIKey(auth.WithAPIKeyName(apiKeyName, apiPrivateKey))
if err != nil {
log.Fatalf("error loading API key: %s", err.Error())
}
// Creates the Coinbase Staking API client.
stakingClient, err := client.New(ctx, options.WithAPIKey(apiKey))
if err != nil {
log.Fatalf("error instantiating staking client: %s", err.Error())
}
req := &api.CreateWorkflowRequest{
Workflow: &api.Workflow{
Action: "protocols/ethereum_kiln/networks/holesky/actions/stake",
StakingParameters: &api.Workflow_EthereumKilnStakingParameters{
EthereumKilnStakingParameters: &api.EthereumKilnStakingParameters{
Parameters: &api.EthereumKilnStakingParameters_StakeParameters{
StakeParameters: &api.EthereumKilnStakeParameters{
StakerAddress: "0xdb816889F2a7362EF242E5a717dfD5B38Ae849FE",
Amount: &api.Amount{
Value: "20",
Currency: "ETH",
},
},
},
},
},
},
}
workflow, err := stakingClient.Orchestration.CreateWorkflow(ctx, req)
if err != nil {
log.Fatalf("couldn't create workflow: %s", err.Error())
}
marshaled, err := protojson.MarshalOptions{Indent: " ", Multiline: true}.Marshal(workflow)
if err != nil {
log.Fatalf("error marshaling reward: %s", err.Error())
}
log.Printf("Workflow created: \n%s", marshaled)
}