OnchainPay SDK is a comprehensive JavaScript library designed to streamline the integration of blockchain-based payment solutions into various applications. This SDK provides developers with the tools necessary to facilitate secure, transparent, and efficient transactions on supported blockchain networks.
Key Features:
- Ease of Integration: Simplifies the process of adding blockchain payment capabilities to your applications.
- Security: Ensures high-level security for all transactions using blockchain technology.
- Transparency: Leverages the transparency of blockchain networks to provide clear and verifiable transaction records.
- Multi-Network Support: Supports multiple blockchain networks, providing flexibility and scalability.
For detailed documentation, installation guides, and API references, please visit OnchainPay Documentation.
This package makes it easy OnChainPay Api.
go get github.com/onchainpay/go-sdk
Go to your personal account https://ocp.onchainpay.io/api-keys and get api-keys.
Substitute keys in class call:
package main
import (
"context"
onchainpay_sdk "github.com/onchainpay/go-sdk"
)
func main() {
client := onchainpay_sdk.New("__PUBLIC_KEY__", "__PRIVATE_KEY__")
}
You can test your signature within this method.
checkSignature := client.Base.CheckSignature(context.Background())
if !checkSignature.Success {
panic(checkSignature.Error)
}
if checkSignature.Response.CheckSignatureResult {
fmt.Println("Signature correct")
} else {
fmt.Println("Signature incorrect", checkSignature.Response.Errors)
}
Get list of available currencies for depositing/withdrawing
availableCurrencies := client.Base.AvailableCurrencies(context.Background())
if !availableCurrencies.Success {
panic(availableCurrencies.Error)
}
list := *availableCurrencies.Response
for _, currency := range list {
fmt.Println("%s (%s) = %s", currency.Currency, currency.Alias, currency.PriceUSD)
if len(currency.Networks) > 0 {
fmt.Println("\tnetworks:");
for _, network := range currency.Networks {
fmt.Println("\t\t%s (%s)", network.Name, network.Alias)
}
}
}
Get price rate from one currency to another
price := client.Base.PriceRate(context.Background(), "ETH", "USDT")
if !price.Success {
panic(price.Error)
}
fmt.Println("Price: %s", price.Response)
Get info about advanced balance
balance := client.AdvancedBalance.AdvancedBalance(context.Background())
if !balance.Success {
panic(balance.Error)
}
fmt.Println("[%s] (%s)\n\tAvalable for deposit: %s", balance.Response.AdvancedBalanceId, balance.Response.Currency, string.Join(balance.Response.AvailableCurrenciesForDeposit, ", "))
package main
import (
"context"
"errors"
"github.com/onchainpay/go-sdk"
"github.com/onchainpay/go-sdk/types/requests"
)
func main() {
orderLink, err := createOrder("USDT", "tron", "1000")
if err != nil {
panic(err)
}
//
}
func createOrder(currency, network, amount string) (string, error) {
ctx := context.Background()
client := onchainpay_sdk.New("__PUBLIC_KEY__", "__PRIVATE_KEY__")
order := client.Orders.MakeOrder(ctx, requests.CreateOrder{
Currency: currency,
Network: network,
Amount: amount,
ErrorWebhook: "https://merchant.domain/webhook-url",
SuccessWebhook: "https://merchant.domain/webhook-url",
ReturnUrl: "https://merchant.domain",
Order: "Order #1234567",
Description: "Buy some item",
})
if !order.Success {
return "", errors.New("Error on create order: " + order.Error.Message)
}
return order.Response.Link, nil
}
package main
import (
"context"
"errors"
"github.com/onchainpay/go-sdk"
"github.com/onchainpay/go-sdk/types/requests"
)
func main() {
autoSwapId, err := makeWithdrawal("USDT", "tron", "TUfVHn...DDC", "100")
if err != nil {
panic(err)
}
//
}
func makeWithdrawal(currency, network, address, amount string) (string, error) {
ctx := context.Background()
client := onchainpay_sdk.New("__PUBLIC_KEY__", "__PRIVATE_KEY__")
swap := client.AutoSwaps.Create(ctx, requests.CreateAutoSwap{
Address: address,
Currency: currency,
Network: network,
AmountTo: amount,
WebhookUrl: "https://merchant.domain/webhook-url",
})
if !swap.Success {
return "", errors.New("Error on make withdrawal: " + swap.Error.Message)
}
return swap.Response.Id, nil
}