0.0.2 • Published 2 years ago

crypto-bot-js v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

CryptoBotJs

NPM Module for Crypto Pay API published for contest.

Installing

Using npm:

$ npm install crypto-bot-js

Using yarn:

$ yarn add crypto-bot-js

Usage

Javascript

//Import module as
const cb = require('crypto-bot-js');

//Then create new instance like
const cryptoBot = new cb.CryptoBot({
  target: 'testnet', //or mainnet
  token: 'YOUR-TOKEN_HERE' //Example 3274:AAOBNJIheTfZ3Gwp3lTH4IwxAYXNnA38M5u
});

//And then you can call any method you want like
cryptoBot.getMe().then((r) => {
  console.log(`My App name is ${r.name}`);
});

Typescript

import {CryptoBot, CryptoBotApp} from 'crypto-bot-js';

//Then you should create a new instance of CryptoBot
const cryptoBot = new CryptoBot({
  target: 'testnet',
  token: 'YOUR-TOKEN_HERE' //Example 3274:AAOBNJIheTfZ3Gwp3lTH4IwxAYXNnA38M5u
});

//Here you can execute any method you want.
cryptoBot.getMe().then((r: CryptoBotApp) => {
  console.log(`My App name is ${r.name}`);
});

Methods

MethodDescriptionRequest ParamsResponse Result
getMeA simple method for testing your app's authentication tokenNoneCryptoBotApp
getBalanceUse this method to get balance of your appNoneArray of CryptoBotBalance
getCurrenciesUse this method to get supported currenciesNoneArray of CryptoBotCurrency
getExchangeRatesUse this method to get exchange rates of supported currencies.NoneArray of CryptoBotExchangeRate
createInvoiceUse this method to create a new invoiceCryptoBotInvoiceInputCryptoBotInvoice
getInvoicesUse this method to get invoices of your appCryptoBotGetInvoicesInputCryptoBotGetInvoicesResult
confirmPaymentUse this method to confirm paid invoice of your app.CryptoBotConfirmPaymentInputCryptoBotPayment
getPaymentsUse this method to get paid and unconfirmed invoices of your appCryptoBotGetPaymentsInputCryptoBotGetPaymentsResult

Request Parameters

These are the parameters you send in your request.

CryptoBotConfirmPaymentInput

NameTypeOptionalDefaultDescription
invoice_idnumberNoNone

CryptoBotGetInvoicesInput

NameTypeOptionalDefaultDescription
assetCryptoBotAssetYesNoneCurrency code.
invoice_idsstringYesNoneInvoice IDs separated by comma.
statusstringYesNoneStatus of invoices. Available statusses active or paid. Default all statusses.
offsetnumberYes0Offset needed to return a specific subset of invoices.
countnumberYes100Number of invoices to return. Default 100, max 1000.

CryptoBotGetPaymentsInput

NameTypeOptionalDefaultDescription
offsetnumberYes0Offset needed to return a specific subset of invoices.
countnumberYes100Number of invoices to return.

CryptoBotInvoiceInput

NameTypeOptionalDefaultDescription
assetCryptoBotAssetNoNoneCurrency code.
amountstringNoNoneAmount of the invoice in float. For example 125.50
descriptionstringYesNoneDescription of the invoice. Up to 1024 symbols
paid_btn_name'viewItem ' or 'openChannel' or 'openBot' or 'callback'YescallbackThis button will be shown when your invoice was paid
paid_btn_urlstringYesNoneThis is required when you use paid_btn_name. Paid button URL.You can set any payment success link (for example link on your bot). Start with https or http.
payloadstringYesNoneSome data. User ID, payment id, or any data you want to attach to the invoice.
allow_commentsbooleanYestrueAllow adding comments when paying an invoice.
allow_anonymousbooleanYestrueAllow pay invoice as anonymous

Response Parameters

These are the parameters contained in a response of your request.

CryptoBotApp

NameTypeDescription
app_idstring
namestring
payment_processing_bot_usernamestring

CryptoBotAsset

Supported assets are

BTC, TON, ETH (only testnet), USDT, USDC, BUSD.

CryptoBotBalance

NameTypeDescription
currency_codestring
availablestring

CryptoBotCurrency

NameTypeDescription
is_blockchainboolean
is_stablecoinboolean
is_fiatboolean
namestring
codestring
urlstring
decimalsnumber

CryptoBotExchangeRate

NameTypeDescription
is_validboolean
sourcestring
targetstring
ratestring

CryptoBotGetInvoicesResult

NameTypeDescription
countnumber
itemsArray of CryptoBotInvoice

CryptoBotGetPaymentsResult

NameTypeDescription
countnumber
itemsArray of CryptoBotPayment

CryptoBotInvoice

NameTypeDescription
invoice_idnumber
statusstring
hashstring
assetCryptoBotAsset
amountstring
pay_urlstring
created_atstring
allow_commentsboolean
allow_anonymousboolean
is_confirmedboolean

CryptoBotPayment

NameTypeDescription
invoice_idnumber
statusstring
hashstring
assetCryptoBotAsset
amountstring
pay_urlstring
created_atstring
paid_atstring
allow_commentsboolean
allow_anonymousboolean
is_confirmedboolean
confirmed_atstring or undefinedWon't be available in array of getPayments()

Tests

Run

yarn test

Things to consider before running tests:

  • For the confirmTest to pass you need to manually pay for invoice using CryptoTestnetBot
  • For the getPayments to pass you need to at have at least one unconfirmed payment.
  • Also, you need to have your own app key since I may delete my app any time. You can get here.