package main
import (
"context"
"encoding/json"
"fmt"
"os"
coboWaas2 "github.com/CoboGlobal/cobo-waas2-go-sdk/cobo_waas2"
"github.com/CoboGlobal/cobo-waas2-go-sdk/cobo_waas2/crypto"
)
func main() {
// Specify the wallet type of the wallet to be created as Custodial Wallet.
walletType, err := coboWaas2.NewWalletTypeFromValue("Custodial")
if err != nil {
fmt.Fprintf(os.Stderr, "Error when new `WalletType``: %v\n", err)
return
}
// Specify the wallet sub-type of the wallet to be created as Asset Wallet.
walletSubType, err := coboWaas2.NewWalletSubtypeFromValue("Asset")
if err != nil {
fmt.Fprintf(os.Stderr, "Error when new `WalletSubType``: %v\n", err)
return
}
createWalletParams := coboWaas2.CreateWalletParams{
CreateCustodialWalletParams: coboWaas2.NewCreateCustodialWalletParams(
// Specify the name of the wallet to be created.
"My WaaS 2.0 Wallet for doc test",
*walletType,
*walletSubType,
)}
configuration := coboWaas2.NewConfiguration()
apiClient := coboWaas2.NewAPIClient(configuration)
ctx := context.Background()
// Select the environment tha you use and comment out the other line of code.
ctx = context.WithValue(ctx, coboWaas2.ContextEnv, coboWaas2.DevEnv)
// ctx = context.WithValue(ctx, coboWaas2.ContextEnv, coboWaas2.ProdEnv)
ctx = context.WithValue(ctx, coboWaas2.ContextPortalSigner, crypto.Ed25519Signer{
// Replace `<YOUR_API_SECRET>` with your own API secret.
Secret: "<YOUR_API_SECRET>",
})
// Call the Create wallet operation.
resp, r, err := apiClient.WalletsAPI.CreateWallet(ctx).CreateWalletParams(createWalletParams).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `WalletsAPI.CreateWallet``: %v\n", err)
if apiErr, ok := err.(*coboWaas2.GenericOpenAPIError); ok {
fmt.Fprintf(os.Stderr, "Error response: %s\n", string(apiErr.Body()))
}
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return
}
// Handle response from `CreateWallet`.
respJson, _ := json.MarshalIndent(resp.GetActualInstance(), "", " ")
fmt.Fprintf(os.Stdout, "Response from `WalletsAPI.CreateWallet`: \n%s", string(respJson))
}