cryptapi

package module
v0.0.0-...-3a28f6d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 4 Imported by: 0

README

CRYPTAPI GO LANG WRAPPER

An idiomatic wrapper written over the core cryptapi endpoints

cryptapi docs


Installation

To install the SDK

$ go get github.com/AnnonaOrg/pkg/cryptapi

Usage

Initiate a crypt instance to keep track of transactions per orders, users or vendors define your preffered criteria and specify it using a base call back webhook and querry params eg: "www.callback.com/?order_id=1&user_id=10"

  • coin - currency to accept payment with this instance.
  • ownAddress - the address to recieve payments, multiple wallets can be specified using this format, <percentage_1>@<address_1>|<percentage_2>@<address_2> max of 20 wallets and all percentages should add up to 100%
  • callBackUrl - the base url for the webhook.
  • callBackParams - unique callback params.
  • urlParams - request params.

Returns - a pointer to the payment instance.

link to endpoint doc

package main

import (
  "fmt"

  "github.com/AnnonaOrg/pkg/cryptapi"
)

func main() {
    // create an instance of the SDK wrapper
    coin := "btc" 
    ownAddress := "bc1qcpxcm8cf52uv865j6qugl82twgy0lz88sfrpk4" 
    callBackUrl := "https://www.callbackexampleurl.com" 
    // eg of call back params used to make callback url unique
    // define your own params
    callBackParams := map[string]string{
		"user_id":  "10",
		"order_id": "12345",
	} 
    // eg of request params used to send requests
    urlParams := map[string]string{
		"multi_chain": "1",
	} 

    ci := cryptapi.InitCryptWrapper(
        coin, // the coin used in the instance
        ownAddress, // address to recieve payment
        callBackUrl, // payment notification webhook
        urlParams, // url querry parameters
        callBackParams // parameters to add to 
        )
}

Generating a Payment Address

Generating an address provides a way to recieve and track payment related to a unique callback url

Returns - an address and an error

link to endpoint doc

    // generate the payment addresss
    address, err := ci.GenPaymentAdress()
    if err != nil {
      fmt.Println("while generating payment wallet:", err)
    } else {
      fmt.Println("payment wallet:", address)
    }

Checking Callback Logs

Logs returns the history of transaction related to a unique call back url.

Returns - the logs and an error

Before checking logs ensure you have generated a payment address using ci.GenPaymentAdress()

link to endpoint doc

    // check payment history
    history, err := ci.CheckLogs()
    if err != nil {
      fmt.Println("while fetching callback history:", err)
    } else {
      fmt.Println("callback history:", history)
    }

Generating a QR Code

Generates a qr code for the specified transaction.

  • size - The size of the qr code in pixels.
  • value - The transaction price.

Returns the qr code and a error.

link to endpoint doc

Before generating a qr code ensure you have generated a payment address using ci.GenPaymentAdress()

    // generate payment qr code
    size := "300"
    value := "100"
    qr, err := ci.GenQR(
      value, // the quantity being charged may be left empty 
      size // the pixel size of the qr code
      )
    if err != nil {
      fmt.Println("while generating qr code:", err)
    } else {
      fmt.Println("qr code:", qr)
    }

Estimating Transaction Fees

Retrieves an estimated price forthe crypto transaction.

  • coin - currency being traded.
  • address count - no of wallets recieving payment.
  • priority - the priority to use when making payments

Returns - estimate and an error

link to endpoint doc

package main

import (
  "fmt"

  "github.com/AnnonaOrg/pkg/cryptapi"
)

func main() {
  coin := "polygon_matic"
  priority := "default"
  add := "1"
  est, err := cryptapi.EstTransactionFee(
    coin, // currency being traded 
    add, // no of addresses to send to
    priority // the priority taken when disbursing payment
    )
  if err != nil {
      fmt.Println("while fetching callback history:", err)
    } else {
      fmt.Println("estimated transaction fee:", est)
    }
}

Converting Between Currencies

Converts between fiat or crypto currencies.

  • coin - the currency being converted.
  • value - quantity to compare.
  • to - the currency to convert to

Returns - the conversion rate and an error.

link to endpoint doc

package main

import (
  "fmt"

  "github.com/AnnonaOrg/pkg/cryptapi"
)

func main() {
  coin := "btc"
  value := "1"
  from := "USD"
  conv, err := cryptapi.Convert(
    coin, // default currency
    value, // amount
    from // currency to convert to
    )
  if err != nil {
      fmt.Println("while converting:", err)
    } else {
      fmt.Println("converted:", conv)
    }
}

Documentation

Overview

* go lang wrapper over cryptapi endpoints * @author - Joseph Folayan * @email - folayanjoey@gmail.com * @github - github.com\joey1123455

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(coin string, value string, from string) (map[string]any, error)

* Convert - This method allows you to easily convert prices from FIAT to Crypto or even between cryptocurrencies * @coin - currency to convert to * @value - the amount to convert * @from - currency to convert from * returns - json response and error

func EstTransactionFee

func EstTransactionFee(coin string, address string, priority string) (map[string]any, error)

* EstTransactionFee - returns the estimated value for a crypto transaction * @coin - the coin being transacted in * @adress - no of address being credited * @priority - credit priority settings * returns - response data or error

Types

type Crypt

type Crypt struct {
	Coin         string
	OwnAddress   string
	CallBack     string
	Params       map[string]string
	CaParams     map[string]string
	PaymentAddrs string
}

* Crypt - an instance representing the connection to the crypt api * @Coin - the currency to transact in * @OwnAddress - the wallet to recieve payment * @CallBack - url to send the request status * @Params - url querry parrams * @CaParams - querry params * @PaymentAddrs - the wallet to send payment to

func InitCryptWrapper

func InitCryptWrapper(coin, ownAddress, callBack string, params, caParams map[string]string) *Crypt

* InitCryptWrapper - creates the crypt request instance * @coin - the currency to transact in * @ownAddress - the wallet to recieve payment * @callBack - url to send the request status * @paymentAddrs - the wallet to send payment to * @params - url querry parrams * @caParams - querry params * returns - ptr to crypt instance

func (*Crypt) CheckLogs

func (w *Crypt) CheckLogs() (map[string]any, error)

* CheckLogs - provides logs for transactions sent to a payment wallet * @w - ptr to crypt instance (reciever method) * returns - logs or error

func (*Crypt) GenPaymentAdress

func (w *Crypt) GenPaymentAdress() (string, error)

* GenPaymentAdress - creates the address for customer to pay too * @w - crypt instance (reciever method) * returns - payment wallet or error

func (*Crypt) GenQR

func (w *Crypt) GenQR(value string, size string) (map[string]any, error)

* GenQR - generates the qr code for the transaction * @value - qr value * @w - crypt instance * @size - qr code size * returns qr code or error

type CryptWrapper

type CryptWrapper interface {
}

* CryptWrapper - an interface defining the crypt api library * @GenPaymentAdress - returns a payment wallet address * @CheckLogs - checks payment logs for requets * @GenQR - generates a qr code for payment

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL