From b3ece635134e4f594307cac95f345af9815cb9ce Mon Sep 17 00:00:00 2001 From: Andrew Min Date: Tue, 20 Feb 2024 10:06:46 -0500 Subject: [PATCH] some more examples --- examples/signing/sign_raw_payload/main.go | 2 +- examples/signing/sign_transaction/main.go | 4 +- examples/wallets/create_wallet/main.go | 51 +++++++++++++++++++ .../wallets/create_wallet_accounts/main.go | 49 ++++++++++++++++++ 4 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 examples/wallets/create_wallet/main.go create mode 100644 examples/wallets/create_wallet_accounts/main.go diff --git a/examples/signing/sign_raw_payload/main.go b/examples/signing/sign_raw_payload/main.go index 05a72e9..446cd8b 100644 --- a/examples/signing/sign_raw_payload/main.go +++ b/examples/signing/sign_raw_payload/main.go @@ -1,4 +1,4 @@ -// Package main demonstrates an API client which returns the UserID of its API key. +// Package main demonstrates an API client which signs a raw payload with a private key ID or wallet account. package main import ( diff --git a/examples/signing/sign_transaction/main.go b/examples/signing/sign_transaction/main.go index 91d272e..0ea5f4b 100644 --- a/examples/signing/sign_transaction/main.go +++ b/examples/signing/sign_transaction/main.go @@ -22,14 +22,14 @@ func main() { timestamp := time.Now().UnixMilli() timestampString := strconv.FormatInt(timestamp, 10) - var privateKeyID string + var sighWith string // can be either a private key ID or a wallet account address var unsignedTransaction string // no 0x prefix necessary pkParams := signing.NewSignTransactionParams().WithBody(&models.SignTransactionRequest{ OrganizationID: client.DefaultOrganization(), TimestampMs: ×tampString, Parameters: &models.SignTransactionIntentV2{ - SignWith: &privateKeyID, + SignWith: &sighWith, Type: models.TransactionTypeEthereum.Pointer(), UnsignedTransaction: &unsignedTransaction, }, diff --git a/examples/wallets/create_wallet/main.go b/examples/wallets/create_wallet/main.go new file mode 100644 index 0000000..d1a38e9 --- /dev/null +++ b/examples/wallets/create_wallet/main.go @@ -0,0 +1,51 @@ +// Package main demonstrates an API client which creates a new wallet with a wallet account. +package main + +import ( + "fmt" + "log" + "strconv" + "time" + + "github.com/tkhq/go-sdk" + "github.com/tkhq/go-sdk/pkg/api/client/wallets" + "github.com/tkhq/go-sdk/pkg/api/models" +) + +func main() { + // NB: make sure to create and register an API key, first. + client, err := sdk.New("default") + if err != nil { + log.Fatal("failed to create new SDK client:", err) + } + + walletName := "New Wallet" + path := "m/44'/60'/0'/0/0" + + timestamp := time.Now().UnixMilli() + timestampString := strconv.FormatInt(timestamp, 10) + + params := wallets.NewCreateWalletParams().WithBody(&models.CreateWalletRequest{ + OrganizationID: client.DefaultOrganization(), + Parameters: &models.CreateWalletIntent{ + WalletName: &walletName, + Accounts: []*models.WalletAccountParams{ + { + AddressFormat: models.AddressFormatEthereum.Pointer(), + Curve: models.CurveSecp256k1.Pointer(), + Path: &path, + PathFormat: models.PathFormatBip32.Pointer(), + }, + }, + }, + TimestampMs: ×tampString, + Type: (*string)(models.ActivityTypeCreateWallet.Pointer()), + }) + + resp, err := client.V0().Wallets.CreateWallet(params, client.Authenticator) + if err != nil { + log.Fatal("failed to make Wallets CreateWallet request:", err) + } + + fmt.Printf("New wallet: %v\n", resp.Payload.Activity.Result.CreateWalletResult.WalletID) +} diff --git a/examples/wallets/create_wallet_accounts/main.go b/examples/wallets/create_wallet_accounts/main.go new file mode 100644 index 0000000..c9debb4 --- /dev/null +++ b/examples/wallets/create_wallet_accounts/main.go @@ -0,0 +1,49 @@ +// Package main demonstrates an API client which creates new wallet accounts. +package main + +import ( + "fmt" + "log" + "strconv" + "time" + + "github.com/tkhq/go-sdk" + "github.com/tkhq/go-sdk/pkg/api/client/wallets" + "github.com/tkhq/go-sdk/pkg/api/models" +) + +func main() { + // NB: make sure to create and register an API key, first. + client, err := sdk.New("default") + if err != nil { + log.Fatal("failed to create new SDK client:", err) + } + + path := "m/44'/60'/0'/0/0" + + timestamp := time.Now().UnixMilli() + timestampString := strconv.FormatInt(timestamp, 10) + + params := wallets.NewCreateWalletAccountsParams().WithBody(&models.CreateWalletAccountsRequest{ + OrganizationID: client.DefaultOrganization(), + Parameters: &models.CreateWalletAccountsIntent{ + Accounts: []*models.WalletAccountParams{ + { + AddressFormat: models.AddressFormatEthereum.Pointer(), + Curve: models.CurveSecp256k1.Pointer(), + Path: &path, + PathFormat: models.PathFormatBip32.Pointer(), + }, + }, + }, + TimestampMs: ×tampString, + Type: (*string)(models.ActivityTypeCreateWalletAccounts.Pointer()), + }) + + resp, err := client.V0().Wallets.CreateWalletAccounts(params, client.Authenticator) + if err != nil { + log.Fatal("failed to make Wallets CreateWalletAccounts request:", err) + } + + fmt.Printf("New wallet account: %v\n", resp.Payload.Activity.Result.CreateWalletAccountsResult.Addresses[0]) +}