Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Feb 17, 2024
1 parent f49bf8f commit b505df8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
Type: models.TransactionTypeEthereum.Pointer(),
UnsignedTransaction: &unsignedTransaction,
},
Type: (*string)(models.ActivityTypeSignTransaction.Pointer()),
Type: (*string)(models.ActivityTypeSignTransactionV2.Pointer()),
})

signResp, err := client.V0().Signing.SignTransaction(pkParams, client.Authenticator)
Expand Down
45 changes: 45 additions & 0 deletions examples/signing/sign_transaction/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Package main demonstrates an API client which signs a transaction with a private key ID or wallet account.
package main

import (
"fmt"
"log"
"strconv"
"time"

"github.com/tkhq/go-sdk"
"github.com/tkhq/go-sdk/pkg/api/client/signing"
"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)
}

timestamp := time.Now().UnixMilli()
timestampString := strconv.FormatInt(timestamp, 10)

var privateKeyID string
var unsignedTransaction string // no 0x prefix necessary

pkParams := signing.NewSignTransactionParams().WithBody(&models.SignTransactionRequest{
OrganizationID: client.DefaultOrganization(),
TimestampMs: &timestampString,
Parameters: &models.SignTransactionIntentV2{
SignWith: &privateKeyID,
Type: models.TransactionTypeEthereum.Pointer(),
UnsignedTransaction: &unsignedTransaction,
},
Type: (*string)(models.ActivityTypeSignTransactionV2.Pointer()),
})

signResp, err := client.V0().Signing.SignTransaction(pkParams, client.Authenticator)
if err != nil {
log.Fatal("failed to make SignTransaction request:", err)
}

fmt.Printf("Signed tx: %v\n", *signResp.Payload.Activity.Result.SignTransactionResult.SignedTransaction)
}

0 comments on commit b505df8

Please sign in to comment.