package main
import (
"context"
"fmt"
"log"
hypermid "github.com/hypermid/sdk-go"
)
func main() {
client := hypermid.NewClient(hypermid.Config{
APIKey: "hm_live_abc123def456",
Timeout: 30 * time.Second,
})
ctx := context.Background()
// Get supported chains
chains, err := client.GetChains(ctx)
if err != nil {
log.Fatal(err)
}
for _, chain := range chains.Chains {
fmt.Printf("%s (ID: %d)\n", chain.Name, chain.ID)
}
// Get a quote
quote, err := client.GetQuote(ctx, &hypermid.QuoteRequest{
FromChain: 1,
ToChain: 42161,
FromToken: "0x0000000000000000000000000000000000000000",
ToToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
FromAmount: "1000000000000000000",
FromAddress: "0xYourAddress",
Slippage: 0.03,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Output: %s %s\n", quote.Estimate.ToAmount, quote.Action.ToToken.Symbol)
fmt.Printf("Via: %s\n", quote.Tool)
// Execute the swap
exec, err := client.Execute(ctx, &hypermid.ExecuteRequest{
FromChain: 1,
ToChain: 42161,
FromToken: "0x0000000000000000000000000000000000000000",
ToToken: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
FromAmount: "1000000000000000000",
FromAddress: "0xYourAddress",
ToAddress: "0xYourAddress",
Slippage: 0.03,
})
if err != nil {
log.Fatal(err)
}
if exec.TransactionRequest != nil {
fmt.Printf("Sign and send tx to: %s\n", exec.TransactionRequest.To)
}
}