npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@samocodes/cryptapi

v1.0.3

Published

Node.js library for integrating with CryptAPI's payment gateway.

Downloads

278

Readme

| NodeJS Implementation of CryptAPI's Payment Gateway

This project provides a Node.js implementation of CryptAPI's payment gateway, ensuring type safety with TypeScript. The implementation includes features to handle cryptocurrency payments, fetch supported coins, generate payment addresses, create QR codes for payments, check payment logs, and convert currency values.

Features

  • Type Safety: All functionalities are implemented with TypeScript, ensuring robust type safety.
  • Supported Coins: Fetch a list of supported cryptocurrencies.
  • Payment Address Generation: Generate new addresses for receiving payments.
  • QR Code Generation: Generate QR codes for cryptocurrency payments.
  • Payment Logs: Check logs for received payments.
  • Currency Conversion: Convert values between different cryptocurrencies and fiat currencies.
  • Estimated Fees: Fetch estimated transaction fees for supported cryptocurrencies.

Installation 📦

You can easily install it:

npm install @samocodes/cryptapi
yarn add @samocodes/cryptapi
pnpm add @samocodes/cryptapi
bun add @samocodes/cryptapi

Usage

Here's an example of how to use this package:

import { CryptAPI } from "@samocodes/cryptapi";

const cryptAPI = new CryptAPI(
  "btc", // Cryptocurrency
  "your-bitcoin-address", // Your own crypto address
  "https://your-webhook-url.com/callback", // Webhook URL
  { orderId: 12345 }, // Additional parameters
  { customParam1: "value1" }, // Custom CryptAPI parameters
);

async function main() {
  try {
    const address = await cryptAPI.createAddress();
    console.log("Payment address:", address);

    const logs = await cryptAPI.checkLogs();
    console.log("Payment logs:", logs);

    // static methods
    const qrCode = await CryptAPI.fetchQRCode(
      "btc",
      "crypto-address",
      100,
      256,
    );
    console.log("QR Code:", qrCode);

    const serviceInfo = await CryptAPI.fetchServiceInfo(true);
    console.log("Service Information:", serviceInfo);

    const estimatedFees = await CryptAPI.fetchEstimatedFees("btc", 2, "fast");
    console.log("Estimated Fees:", estimatedFees);

    const conversion = await CryptAPI.fetchConversion("btc", 1000, "usd");
    console.log("Conversion Information:", conversion);
  } catch (error) {
    console.error("Error:", error);
  }
}

main();

API Reference

CryptAPI

Constructor
new CryptAPI(
  coin: string,
  address: string,
  callbackUrl: string,
  params?: Record<string, string | number>,
  caParams?: CryptAPIParams
);
  • coin: The cryptocurrency you wish to use (e.g., 'btc', 'eth').
  • address: Your own cryptocurrency address to receive payments.
  • callbackUrl: The webhook URL to receive payment notifications.
  • params: Additional parameters to identify the payment.
  • caParams: Custom parameters that will be passed to CryptAPI.
Methods
createAddress()

Creates a new address to receive payments.

async createAddress(): Promise<string>;
fetchQRCode(coin: string, address: string, value: number | null, size: number = 512)

Fetches a QR code for the specified value and size.

async fetchQRCode(value: number | null, size?: number): Promise<GenerateQR>;
checkLogs()

Checks the payment logs.

async checkLogs(): Promise<PaymentLogs>;
fetchServiceInfo(prices?: boolean)

Fetches service information.

static async fetchServiceInfo(prices?: boolean): Promise<ServiceInformation<typeof prices>>;
fetchEstimatedFees(coin: string, addresses?: number, priority?: Priority)

Fetches estimated fees for transactions.

static async fetchEstimatedFees(coin: string, addresses?: number, priority?: Priority): Promise<EstimatedFees>;
fetchConversion(coin: string, value: number, from: string)

Fetches conversion information for a given value.

static async fetchConversion(coin: string, value: number, from: string): Promise<Conversion>;

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.