Skip to main content

Overview

The Devdraft Go SDK provides a complete client library for integrating payment processing, customer management, and webhook functionality into your Go applications.

Type-Safe

Strong typing with Go’s type system and struct tags

Context-Aware

Built-in support for Go’s context package for cancellation and timeouts

Comprehensive

Access to all Devdraft API endpoints and features

Idiomatic Go

Follows Go best practices and conventions

Installation

go get github.com/devdraftengineer/go

Requirements

  • Go 1.19 or higher

Quick Start

package main

import (
    "context"
    "fmt"
    "os"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    // Create configuration
    cfg := devdraft.NewConfiguration()
    cfg.Servers = devdraft.ServerConfigurations{
        {
            URL: "https://api.devdraft.ai",
        },
    }
    
    // Create API client
    client := devdraft.NewAPIClient(cfg)
    
    // Setup authentication context
    ctx := context.WithValue(
        context.Background(),
        devdraft.ContextAPIKeys,
        map[string]devdraft.APIKey{
            "x-client-key": {
                Key: os.Getenv("DEVDRAFT_CLIENT_KEY"),
            },
            "x-client-secret": {
                Key: os.Getenv("DEVDRAFT_CLIENT_SECRET"),
            },
        },
    )
    
    // Use the API
    transfer, resp, err := client.TransfersAPI.TransferControllerCreateDirectWalletTransfer(ctx).
        CreateDirectWalletTransferDto(devdraft.CreateDirectWalletTransferDto{
            WalletId:           "your-wallet-id",
            Network:            "solana",
            StableCoinCurrency: "usdc",
            Amount:             100.00,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Transfer created: %s\n", *transfer.Id)
}

API Services

The SDK is organized into API services, each handling a specific domain:
API ServiceDescription
APIHealthAPIService health checks and status monitoring
AppBalancesAPIQuery application balances across stablecoins
CustomersAPICustomer management and KYC operations
ExchangeRatesAPIReal-time currency exchange rates
InvoicesAPIInvoice creation and management
LiquidationAddressesAPICryptocurrency liquidation addresses
PaymentIntentsAPIPayment intent creation for bank and stablecoin
PaymentLinksAPIGenerate and manage payment links
ProductsAPIProduct catalog management
TaxesAPITax configuration and management
TestPaymentsAPITest payment processing in sandbox
TransfersAPIInitiate and manage fund transfers
WalletsAPIWallet management and balances
WebhooksAPIWebhook configuration and management

API Health

Monitor service health and availability.

Methods

HealthControllerCheckV0(ctx)

Authenticated health check endpoint requiring API credentials.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    client := devdraft.NewAPIClient(devdraft.NewConfiguration())
    
    resp, err := client.APIHealthAPI.HealthControllerCheckV0(ctx).Execute()
    if err != nil {
        fmt.Printf("Health check failed: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Println("Service is healthy and authenticated")
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*http.Response, error)

HealthControllerPublicHealthCheckV0(ctx)

Public health check endpoint (no authentication required).
status, resp, err := client.APIHealthAPI.HealthControllerPublicHealthCheckV0(ctx).Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Service status: %s\n", *status.Status)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*PublicHealthResponseDto, *http.Response, error)

App Balances

Query your application’s stablecoin balances.

Methods

BalanceControllerGetAllBalances(ctx)

Get all stablecoin balances for your application.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    balances, resp, err := client.AppBalancesAPI.BalanceControllerGetAllBalances(ctx).Execute()
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("USDC Balance: %v\n", balances.Usdc)
    fmt.Printf("EURC Balance: %v\n", balances.Eurc)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*AllBalancesResponse, *http.Response, error)

BalanceControllerGetUSDCBalance(ctx)

Get USDC balance only.
usdcBalance, resp, err := client.AppBalancesAPI.BalanceControllerGetUSDCBalance(ctx).Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("USDC: %v\n", usdcBalance.Amount)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*AggregatedBalanceResponse, *http.Response, error)

BalanceControllerGetEURCBalance(ctx)

Get EURC balance only.
eurcBalance, resp, err := client.AppBalancesAPI.BalanceControllerGetEURCBalance(ctx).Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("EURC: %v\n", eurcBalance.Amount)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*AggregatedBalanceResponse, *http.Response, error)

Customers

Manage customer records and KYC information.

Methods

CustomerControllerCreate(ctx)

Create a new customer.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    firstName := "John"
    lastName := "Doe"
    email := "john.doe@example.com"
    customerType := "INDIVIDUAL"
    country := "US"
    
    newCustomer, resp, err := client.CustomersAPI.CustomerControllerCreate(ctx).
        CreateCustomerDto(devdraft.CreateCustomerDto{
            FirstName: &firstName,
            LastName:  &lastName,
            Email:     &email,
            Type:      &customerType,
            Country:   &country,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Customer created: %s\n", *newCustomer.Id)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Customer, *http.Response, error)

CustomerControllerFindAll(ctx)

Get all customers with optional filters.
page := int32(1)
limit := int32(20)
status := "ACTIVE"

customers, resp, err := client.CustomersAPI.CustomerControllerFindAll(ctx).
    Page(&page).
    Limit(&limit).
    Status(&status).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

for _, customer := range customers {
    fmt.Printf("%s %s - %s\n", *customer.FirstName, *customer.LastName, *customer.Email)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • Page(*int32) - Page number (optional, default: 1)
  • Limit(*int32) - Items per page (optional, default: 20)
  • Status(*string) - Filter by status (optional)
Returns: ([]Customer, *http.Response, error)

CustomerControllerFindOne(ctx, id)

Get a customer by ID.
customer, resp, err := client.CustomersAPI.CustomerControllerFindOne(ctx, "customer-id-here").Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Customer: %s %s\n", *customer.FirstName, *customer.LastName)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Customer ID
Returns: (*Customer, *http.Response, error)

CustomerControllerUpdate(ctx, id)

Update a customer’s information.
phone := "+1234567890"
address := "123 Main St"

updated, resp, err := client.CustomersAPI.CustomerControllerUpdate(ctx, "customer-id-here").
    UpdateCustomerDto(devdraft.UpdateCustomerDto{
        Phone:   &phone,
        Address: &address,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Customer updated: %s\n", *updated.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Customer ID
Returns: (*Customer, *http.Response, error)

Exchange Rates

Get real-time currency exchange rates.

Methods

ExchangeRateControllerGetExchangeRate(ctx)

Get exchange rate between any two supported currencies.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    from := "USD"
    to := "EUR"
    
    rate, resp, err := client.ExchangeRatesAPI.ExchangeRateControllerGetExchangeRate(ctx).
        From(&from).
        To(&to).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("1 USD = %v EUR\n", *rate.Rate)
    fmt.Printf("Rate expires at: %v\n", *rate.ExpiresAt)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • From(*string) - Source currency code
  • To(*string) - Target currency code
Returns: (*ExchangeRateResponseDto, *http.Response, error)

ExchangeRateControllerGetUSDToEURRate(ctx)

Get USD to EUR exchange rate.
usdToEur, resp, err := client.ExchangeRatesAPI.ExchangeRateControllerGetUSDToEURRate(ctx).Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("USD to EUR: %v\n", *usdToEur.Rate)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*ExchangeRateResponseDto, *http.Response, error)

ExchangeRateControllerGetEURToUSDRate(ctx)

Get EUR to USD exchange rate.
eurToUsd, resp, err := client.ExchangeRatesAPI.ExchangeRateControllerGetEURToUSDRate(ctx).Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("EUR to USD: %v\n", *eurToUsd.Rate)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*ExchangeRateResponseDto, *http.Response, error)

Invoices

Create and manage invoices for your customers.

Methods

InvoiceControllerCreate(ctx)

Create a new invoice.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    customerId := "customer-id"
    dueDate := "2024-12-31"
    
    invoice, resp, err := client.InvoicesAPI.InvoiceControllerCreate(ctx).
        CreateInvoiceDto(devdraft.CreateInvoiceDto{
            CustomerId: &customerId,
            Items: []devdraft.InvoiceProductDto{
                {
                    Description: devdraft.PtrString("Premium Subscription"),
                    Quantity:    devdraft.PtrInt32(1),
                    Price:       devdraft.PtrFloat64(99.99),
                    Currency:    devdraft.PtrString("USD"),
                },
            },
            DueDate: &dueDate,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Invoice created: %s\n", *invoice.Id)
    fmt.Printf("Total: %v\n", *invoice.Total)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Invoice, *http.Response, error)

InvoiceControllerFindAll(ctx)

Get all invoices.
page := int32(1)
limit := int32(50)
status := "UNPAID"

invoices, resp, err := client.InvoicesAPI.InvoiceControllerFindAll(ctx).
    Page(&page).
    Limit(&limit).
    Status(&status).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

for _, invoice := range invoices {
    fmt.Printf("Invoice %s: %v\n", *invoice.Id, *invoice.Total)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • Page(*int32) - Page number (optional)
  • Limit(*int32) - Items per page (optional)
  • Status(*string) - Filter by status (optional)
Returns: ([]Invoice, *http.Response, error)

InvoiceControllerFindOne(ctx, id)

Get an invoice by ID.
invoice, resp, err := client.InvoicesAPI.InvoiceControllerFindOne(ctx, "invoice-id").Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Invoice total: %v\n", *invoice.Total)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Invoice ID
Returns: (*Invoice, *http.Response, error)

InvoiceControllerUpdate(ctx, id)

Update an invoice.
status := "PAID"
paidAt := time.Now().Format(time.RFC3339)

updated, resp, err := client.InvoicesAPI.InvoiceControllerUpdate(ctx, "invoice-id").
    UpdateInvoiceDto(devdraft.UpdateInvoiceDto{
        Status: &status,
        PaidAt: &paidAt,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Invoice updated: %s\n", *updated.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Invoice ID
Returns: (*Invoice, *http.Response, error)

Liquidation Addresses

Manage cryptocurrency liquidation addresses for customers.

Methods

LiquidationAddressControllerCreateLiquidationAddress(ctx, customerId)

Create a new liquidation address for a customer.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    network := "solana"
    currency := "usdc"
    
    address, resp, err := client.LiquidationAddressesAPI.
        LiquidationAddressControllerCreateLiquidationAddress(ctx, "customer-id").
        CreateLiquidationAddressDto(devdraft.CreateLiquidationAddressDto{
            Network:  &network,
            Currency: &currency,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Liquidation address: %s\n", *address.Address)
    fmt.Printf("Network: %s\n", *address.Network)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • customerId: string - Customer ID
Returns: (*LiquidationAddressResponseDto, *http.Response, error)

LiquidationAddressControllerGetLiquidationAddresses(ctx, customerId)

Get all liquidation addresses for a customer.
addresses, resp, err := client.LiquidationAddressesAPI.
    LiquidationAddressControllerGetLiquidationAddresses(ctx, "customer-id").
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

for _, addr := range addresses {
    fmt.Printf("%s: %s\n", *addr.Network, *addr.Address)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • customerId: string - Customer ID
Returns: ([]LiquidationAddressResponseDto, *http.Response, error)

LiquidationAddressControllerGetLiquidationAddress(ctx, customerId, liquidationAddressId)

Get a specific liquidation address.
address, resp, err := client.LiquidationAddressesAPI.
    LiquidationAddressControllerGetLiquidationAddress(ctx, "customer-id", "address-id").
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Address: %s\n", *address.Address)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • customerId: string - Customer ID
  • liquidationAddressId: string - Address ID
Returns: (*LiquidationAddressResponseDto, *http.Response, error)

Payment Intents

Create payment intents for bank and stablecoin payments.

Methods

PaymentIntentControllerCreateBankPaymentIntent(ctx)

Create a bank payment intent.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    customerId := "customer-id"
    amount := 1000.00
    currency := "USD"
    paymentRail := "wire"
    
    intent, resp, err := client.PaymentIntentsAPI.
        PaymentIntentControllerCreateBankPaymentIntent(ctx).
        CreateBankPaymentIntentDto(devdraft.CreateBankPaymentIntentDto{
            CustomerId:  &customerId,
            Amount:      &amount,
            Currency:    &currency,
            PaymentRail: &paymentRail,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Payment intent: %s\n", *intent.Id)
    fmt.Printf("Status: %s\n", *intent.Status)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*PaymentIntent, *http.Response, error)

PaymentIntentControllerCreateStablePaymentIntent(ctx)

Create a stablecoin payment intent.
customerId := "customer-id"
amount := 500.00
currency := "usdc"
network := "solana"

stableIntent, resp, err := client.PaymentIntentsAPI.
    PaymentIntentControllerCreateStablePaymentIntent(ctx).
    CreateStablePaymentIntentDto(devdraft.CreateStablePaymentIntentDto{
        CustomerId: &customerId,
        Amount:     &amount,
        Currency:   &currency,
        Network:    &network,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Stable intent: %s\n", *stableIntent.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*PaymentIntent, *http.Response, error)
Generate and manage payment links for easy customer payments.

Methods

PaymentLinksControllerCreate(ctx)

Create a new payment link.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    name := "Product Purchase"
    amount := 99.99
    currency := "USD"
    
    link, resp, err := client.PaymentLinksAPI.PaymentLinksControllerCreate(ctx).
        CreatePaymentLinkDto(devdraft.CreatePaymentLinkDto{
            Name:     &name,
            Amount:   &amount,
            Currency: &currency,
            Products: []devdraft.PaymentLinkProductDto{
                {
                    Name:     devdraft.PtrString("Premium Plan"),
                    Quantity: devdraft.PtrInt32(1),
                    Price:    devdraft.PtrFloat64(99.99),
                },
            },
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Payment link: %s\n", *link.Url)
    fmt.Printf("Share this link with customers: %s\n", *link.ShortUrl)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*PaymentLink, *http.Response, error)

PaymentLinksControllerFindAll(ctx)

Get all payment links.
page := int32(1)
limit := int32(20)
active := true

links, resp, err := client.PaymentLinksAPI.PaymentLinksControllerFindAll(ctx).
    Page(&page).
    Limit(&limit).
    Active(&active).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

for _, link := range links {
    fmt.Printf("%s: %s\n", *link.Name, *link.Url)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • Page(*int32) - Page number (optional)
  • Limit(*int32) - Items per page (optional)
  • Active(*bool) - Filter by active status (optional)
Returns: ([]PaymentLink, *http.Response, error)

PaymentLinksControllerFindOne(ctx, id)

Get a payment link by ID.
link, resp, err := client.PaymentLinksAPI.PaymentLinksControllerFindOne(ctx, "link-id").Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Link: %s\n", *link.Url)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Payment link ID
Returns: (*PaymentLink, *http.Response, error)

PaymentLinksControllerUpdate(ctx, id)

Update a payment link.
active := false
expiresAt := "2024-12-31T23:59:59Z"

updated, resp, err := client.PaymentLinksAPI.PaymentLinksControllerUpdate(ctx, "link-id").
    UpdatePaymentLinkDto(devdraft.UpdatePaymentLinkDto{
        Active:    &active,
        ExpiresAt: &expiresAt,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Link updated: %s\n", *updated.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Payment link ID
Returns: (*PaymentLink, *http.Response, error)

Transfers

Initiate and manage fund transfers between different payment rails.

Methods

TransferControllerCreateDirectBankTransfer(ctx)

Create a direct bank transfer.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    walletId := "wallet-id"
    paymentRail := "wire"
    sourceCurrency := "usd"
    destinationCurrency := "usdc"
    amount := 1000.00
    
    transfer, resp, err := client.TransfersAPI.TransferControllerCreateDirectBankTransfer(ctx).
        CreateDirectBankTransferDto(devdraft.CreateDirectBankTransferDto{
            WalletId:            &walletId,
            PaymentRail:         &paymentRail,
            SourceCurrency:      &sourceCurrency,
            DestinationCurrency: &destinationCurrency,
            Amount:              &amount,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Transfer created: %s\n", *transfer.Id)
    fmt.Printf("Bank instructions: %+v\n", transfer.SourceDepositInstructions)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Transfer, *http.Response, error) See also: Direct Bank Transfer Guide

TransferControllerCreateDirectWalletTransfer(ctx)

Create a direct wallet transfer.
walletId := "wallet-id"
network := "solana"
stableCoinCurrency := "usdc"
amount := 500.00

transfer, resp, err := client.TransfersAPI.TransferControllerCreateDirectWalletTransfer(ctx).
    CreateDirectWalletTransferDto(devdraft.CreateDirectWalletTransferDto{
        WalletId:           &walletId,
        Network:            &network,
        StableCoinCurrency: &stableCoinCurrency,
        Amount:             &amount,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Transfer created: %s\n", *transfer.Id)
fmt.Printf("Deposit address: %s\n", *transfer.SourceDepositInstructions.ToAddress)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Transfer, *http.Response, error) See also: Direct Wallet Transfer Guide

TransferControllerCreateExternalBankTransfer(ctx)

Create an external bank transfer (from your wallet to external bank).
sourceWalletId := "wallet-id"
destinationBankAccountId := "bank-account-id"
amount := 1000.00
currency := "USD"

transfer, resp, err := client.TransfersAPI.TransferControllerCreateExternalBankTransfer(ctx).
    CreateExternalBankTransferDto(devdraft.CreateExternalBankTransferDto{
        SourceWalletId:           &sourceWalletId,
        DestinationBankAccountId: &destinationBankAccountId,
        Amount:                   &amount,
        Currency:                 &currency,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("External bank transfer: %s\n", *transfer.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Transfer, *http.Response, error)

TransferControllerCreateExternalStablecoinTransfer(ctx)

Create an external stablecoin transfer (from your wallet to external wallet).
sourceWalletId := "wallet-id"
destinationAddress := "0x742d35Cc6Ff82a8C2D8D1Da9da17c7eDfD5bE0a3"
network := "ethereum"
currency := "usdc"
amount := 250.00

transfer, resp, err := client.TransfersAPI.TransferControllerCreateExternalStablecoinTransfer(ctx).
    CreateExternalStablecoinTransferDto(devdraft.CreateExternalStablecoinTransferDto{
        SourceWalletId:     &sourceWalletId,
        DestinationAddress: &destinationAddress,
        Network:            &network,
        Currency:           &currency,
        Amount:             &amount,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("External stablecoin transfer: %s\n", *transfer.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Transfer, *http.Response, error)

TransferControllerCreateStablecoinConversion(ctx)

Convert between different stablecoins or networks.
sourceWalletId := "wallet-id"
destinationWalletId := "wallet-id"
sourceNetwork := "ethereum"
destinationNetwork := "solana"
sourceCurrency := "usdc"
destinationCurrency := "usdc"
amount := 1000.00

conversion, resp, err := client.TransfersAPI.TransferControllerCreateStablecoinConversion(ctx).
    CreateStablecoinConversionDto(devdraft.CreateStablecoinConversionDto{
        SourceWalletId:      &sourceWalletId,
        DestinationWalletId: &destinationWalletId,
        SourceNetwork:       &sourceNetwork,
        DestinationNetwork:  &destinationNetwork,
        SourceCurrency:      &sourceCurrency,
        DestinationCurrency: &destinationCurrency,
        Amount:              &amount,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Conversion ID: %s\n", *conversion.Id)
fmt.Printf("Exchange rate: %v\n", *conversion.ExchangeRate.Rate)
fmt.Printf("Estimated completion: %v\n", *conversion.EstimatedCompletion)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*Conversion, *http.Response, error) See also: Stablecoin Conversion Guide

Wallets

Manage wallets and query balances.

Methods

WalletControllerGetWallets(ctx)

Get all wallets for your application.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    resp, err := client.WalletsAPI.WalletControllerGetWallets(ctx).Execute()
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Println("Wallets retrieved successfully")
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*http.Response, error)
The response contains wallet IDs that you can use for transfers and other operations. In a future SDK version, this will return typed wallet objects.

Webhooks

Configure webhooks to receive real-time event notifications.

Methods

WebhookControllerCreate(ctx)

Create a new webhook.
package main

import (
    "context"
    "fmt"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    url := "https://your-app.com/webhooks/devdraft"
    name := "Production Webhook"
    isActive := true
    encrypted := false
    
    webhook, resp, err := client.WebhooksAPI.WebhookControllerCreate(ctx).
        CreateWebhookDto(devdraft.CreateWebhookDto{
            Url:       &url,
            Name:      &name,
            IsActive:  &isActive,
            Encrypted: &encrypted,
        }).
        Execute()
    
    if err != nil {
        fmt.Printf("Error: %v\n", err)
        return
    }
    defer resp.Body.Close()
    
    fmt.Printf("Webhook ID: %s\n", *webhook.Id)
    fmt.Printf("Signing secret: %s\n", *webhook.SigningSecret)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
Returns: (*WebhookResponseDto, *http.Response, error) See also: Webhooks Overview

WebhookControllerFindAll(ctx)

Get all webhooks.
page := int32(1)
limit := int32(20)
active := true

webhooks, resp, err := client.WebhooksAPI.WebhookControllerFindAll(ctx).
    Page(&page).
    Limit(&limit).
    Active(&active).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

for _, webhook := range webhooks {
    fmt.Printf("%s: %s\n", *webhook.Name, *webhook.Url)
    fmt.Printf("Active: %v\n", *webhook.IsActive)
}
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • Page(*int32) - Page number (optional)
  • Limit(*int32) - Items per page (optional)
  • Active(*bool) - Filter by active status (optional)
Returns: ([]WebhookResponseDto, *http.Response, error)

WebhookControllerFindOne(ctx, id)

Get a webhook by ID.
webhook, resp, err := client.WebhooksAPI.WebhookControllerFindOne(ctx, "webhook-id").Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Webhook: %s\n", *webhook.Name)
fmt.Printf("URL: %s\n", *webhook.Url)
fmt.Printf("Delivery stats: %+v\n", webhook.DeliveryStats)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Webhook ID
Returns: (*WebhookResponseDto, *http.Response, error)

WebhookControllerUpdate(ctx, id)

Update a webhook.
url := "https://your-app.com/webhooks/new-endpoint"
isActive := true

updated, resp, err := client.WebhooksAPI.WebhookControllerUpdate(ctx, "webhook-id").
    UpdateWebhookDto(devdraft.UpdateWebhookDto{
        Url:      &url,
        IsActive: &isActive,
    }).
    Execute()

if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Printf("Webhook updated: %s\n", *updated.Id)
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Webhook ID
Returns: (*WebhookResponseDto, *http.Response, error)

WebhookControllerRemove(ctx, id)

Delete a webhook.
resp, err := client.WebhooksAPI.WebhookControllerRemove(ctx, "webhook-id").Execute()
if err != nil {
    fmt.Printf("Error: %v\n", err)
    return
}
defer resp.Body.Close()

fmt.Println("Webhook deleted")
Parameters:
  • ctx: context.Context - Context for cancellation and timeouts
  • id: string - Webhook ID
Returns: (*http.Response, error)

Error Handling

All SDK methods return errors as the last return value. Handle them appropriately:
package main

import (
    "context"
    "fmt"
    "net/http"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    transfer, resp, err := client.TransfersAPI.TransferControllerCreateDirectWalletTransfer(ctx).
        CreateDirectWalletTransferDto(transferData).
        Execute()
    
    if err != nil {
        // Check if it's an API error with response
        if resp != nil {
            defer resp.Body.Close()
            
            switch resp.StatusCode {
            case http.StatusBadRequest:
                fmt.Printf("Invalid request: %v\n", err)
            case http.StatusUnauthorized:
                fmt.Println("Authentication failed - check your API credentials")
            case http.StatusNotFound:
                fmt.Printf("Resource not found: %v\n", err)
            case http.StatusUnprocessableEntity:
                fmt.Printf("Validation error: %v\n", err)
            case http.StatusTooManyRequests:
                retryAfter := resp.Header.Get("Retry-After")
                fmt.Printf("Rate limited - retry after: %s\n", retryAfter)
            default:
                fmt.Printf("API error: %d - %v\n", resp.StatusCode, err)
            }
        } else {
            // Network or other error
            fmt.Printf("Request error: %v\n", err)
        }
        return
    }
    
    // Success - use the transfer
    fmt.Printf("Transfer created: %s\n", *transfer.Id)
}

Helper Functions

The SDK provides helper functions for creating pointers to primitive types:
// Helper functions available in the SDK
func PtrString(s string) *string
func PtrInt32(i int32) *int32
func PtrInt64(i int64) *int64
func PtrFloat32(f float32) *float32
func PtrFloat64(f float64) *float64
func PtrBool(b bool) *bool

// Usage example
name := devdraft.PtrString("John Doe")
age := devdraft.PtrInt32(30)
active := devdraft.PtrBool(true)
amount := devdraft.PtrFloat64(99.99)

Best Practices

1

Use Context with Timeout

Always use context with timeout for API calls to prevent hanging requests.
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

transfer, resp, err := client.TransfersAPI.TransferControllerCreateDirectWalletTransfer(ctx).
    CreateDirectWalletTransferDto(transferData).
    Execute()
2

Always Close Response Bodies

Use defer to ensure response bodies are closed to prevent resource leaks.
resp, err := client.APIHealthAPI.HealthControllerCheckV0(ctx).Execute()
if err != nil {
    // Handle error
    return
}
defer resp.Body.Close()  // Always close the response body
3

Environment Variables for Credentials

Store API credentials in environment variables, never in source code.
import "os"

ctx := context.WithValue(
    context.Background(),
    devdraft.ContextAPIKeys,
    map[string]devdraft.APIKey{
        "x-client-key": {
            Key: os.Getenv("DEVDRAFT_CLIENT_KEY"),
        },
        "x-client-secret": {
            Key: os.Getenv("DEVDRAFT_CLIENT_SECRET"),
        },
    },
)
4

Check Both Error and Response

Always check both the error and response status code for complete error handling.
result, resp, err := client.CustomersAPI.CustomerControllerCreate(ctx).
    CreateCustomerDto(customerData).
    Execute()

if err != nil {
    if resp != nil {
        defer resp.Body.Close()
        fmt.Printf("HTTP Status: %d\n", resp.StatusCode)
    }
    return err
}
defer resp.Body.Close()
5

Reuse Client Instances

Create a single API client instance and reuse it across your application.
// Bad: Creating new client for each request
func processTransfer() {
    client := devdraft.NewAPIClient(devdraft.NewConfiguration())
    // use client...
}

// Good: Reuse the same client
var client *devdraft.APIClient

func init() {
    cfg := devdraft.NewConfiguration()
    client = devdraft.NewAPIClient(cfg)
}

func processTransfer() {
    // use global client...
}
6

Use Pointer Helper Functions

Use the SDK’s pointer helper functions for cleaner code.
// Instead of this:
name := "John"
customerData := devdraft.CreateCustomerDto{
    FirstName: &name,
}

// Use helper functions:
customerData := devdraft.CreateCustomerDto{
    FirstName: devdraft.PtrString("John"),
    Age:       devdraft.PtrInt32(30),
    Active:    devdraft.PtrBool(true),
}

Testing

Example test using Go’s testing package:
package main

import (
    "context"
    "os"
    "testing"
    
    devdraft "github.com/devdraftengineer/go"
)

func setupClient() *devdraft.APIClient {
    cfg := devdraft.NewConfiguration()
    cfg.Servers = devdraft.ServerConfigurations{
        {
            URL: "https://api.devdraft.ai",
        },
    }
    return devdraft.NewAPIClient(cfg)
}

func setupContext() context.Context {
    return context.WithValue(
        context.Background(),
        devdraft.ContextAPIKeys,
        map[string]devdraft.APIKey{
            "x-client-key": {
                Key: os.Getenv("DEVDRAFT_TEST_CLIENT_KEY"),
            },
            "x-client-secret": {
                Key: os.Getenv("DEVDRAFT_TEST_CLIENT_SECRET"),
            },
        },
    )
}

func TestCreateWebhook(t *testing.T) {
    client := setupClient()
    ctx := setupContext()
    
    webhook, resp, err := client.WebhooksAPI.WebhookControllerCreate(ctx).
        CreateWebhookDto(devdraft.CreateWebhookDto{
            Url:      devdraft.PtrString("https://test.example.com/webhook"),
            Name:     devdraft.PtrString("Test Webhook"),
            IsActive: devdraft.PtrBool(true),
        }).
        Execute()
    
    if err != nil {
        t.Fatalf("Error creating webhook: %v", err)
    }
    defer resp.Body.Close()
    
    if webhook.Id == nil {
        t.Error("Expected webhook ID to be set")
    }
    
    if *webhook.Name != "Test Webhook" {
        t.Errorf("Expected name 'Test Webhook', got '%s'", *webhook.Name)
    }
}

func TestAPIErrorHandling(t *testing.T) {
    client := setupClient()
    ctx := setupContext()
    
    // Try to create transfer with invalid data
    _, resp, err := client.TransfersAPI.TransferControllerCreateDirectWalletTransfer(ctx).
        CreateDirectWalletTransferDto(devdraft.CreateDirectWalletTransferDto{
            WalletId:           devdraft.PtrString("invalid-id"),
            Network:            devdraft.PtrString("invalid-network"),
            StableCoinCurrency: devdraft.PtrString("invalid"),
            Amount:             devdraft.PtrFloat64(-100),  // Invalid amount
        }).
        Execute()
    
    if err == nil {
        t.Error("Expected error for invalid transfer data")
    }
    
    if resp != nil {
        defer resp.Body.Close()
        if resp.StatusCode != 400 && resp.StatusCode != 422 {
            t.Errorf("Expected 400 or 422 status code, got %d", resp.StatusCode)
        }
    }
}

Concurrency

The SDK is safe for concurrent use. You can make multiple API calls concurrently:
package main

import (
    "context"
    "fmt"
    "sync"
    
    devdraft "github.com/devdraftengineer/go"
)

func main() {
    client := devdraft.NewAPIClient(devdraft.NewConfiguration())
    ctx := setupAuthContext()
    
    var wg sync.WaitGroup
    
    // Make multiple concurrent API calls
    for i := 0; i < 5; i++ {
        wg.Add(1)
        go func(index int) {
            defer wg.Done()
            
            customer, resp, err := client.CustomersAPI.CustomerControllerFindOne(
                ctx,
                fmt.Sprintf("customer-%d", index),
            ).Execute()
            
            if err != nil {
                fmt.Printf("Error fetching customer %d: %v\n", index, err)
                return
            }
            defer resp.Body.Close()
            
            fmt.Printf("Fetched customer %d: %s\n", index, *customer.Id)
        }(i)
    }
    
    wg.Wait()
}

Next Steps

SDK Quickstart

Complete integration guide with examples

Transfers

Learn about initiating transfers

Webhooks

Set up webhook notifications

API Reference

Complete REST API documentation