NPM Module for Crypto Pay API published for this contest which I ended up in third place and got rewardered $150.
Using npm:
$ npm install crypto-bot-js
Using yarn:
$ yarn add crypto-bot-js
//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}`);
});
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}`);
});
Method | Description | Request Params | Response Result |
---|---|---|---|
getMe | A simple method for testing your app's authentication token | None | CryptoBotApp |
getBalance | Use this method to get balance of your app | None | Array of CryptoBotBalance |
getCurrencies | Use this method to get supported currencies | None | Array of CryptoBotCurrency |
getExchangeRates | Use this method to get exchange rates of supported currencies. | None | Array of CryptoBotExchangeRate |
createInvoice | Use this method to create a new invoice | CryptoBotInvoiceInput | CryptoBotInvoice |
getInvoices | Use this method to get invoices of your app | CryptoBotGetInvoicesInput | CryptoBotGetInvoicesResult |
confirmPayment | Use this method to confirm paid invoice of your app. | CryptoBotConfirmPaymentInput | CryptoBotPayment |
getPayments | Use this method to get paid and unconfirmed invoices of your app | CryptoBotGetPaymentsInput | CryptoBotGetPaymentsResult |
These are the parameters you send in your request.
Name | Type | Optional | Default | Description |
---|---|---|---|---|
invoice_id | number | No | None |
Name | Type | Optional | Default | Description |
---|---|---|---|---|
asset | CryptoBotAsset | Yes | None | Currency code. |
invoice_ids | string | Yes | None | Invoice IDs separated by comma. |
status | string | Yes | None | Status of invoices. Available statusses active or paid. Default all statusses. |
offset | number | Yes | 0 | Offset needed to return a specific subset of invoices. |
count | number | Yes | 100 | Number of invoices to return. Default 100, max 1000. |
Name | Type | Optional | Default | Description |
---|---|---|---|---|
offset | number | Yes | 0 | Offset needed to return a specific subset of invoices. |
count | number | Yes | 100 | Number of invoices to return. |
Name | Type | Optional | Default | Description |
---|---|---|---|---|
asset | CryptoBotAsset | No | None | Currency code. |
amount | string | No | None | Amount of the invoice in float. For example 125.50 |
description | string | Yes | None | Description of the invoice. Up to 1024 symbols |
paid_btn_name | 'viewItem ' or 'openChannel' or 'openBot' or 'callback' | Yes | callback | This button will be shown when your invoice was paid |
paid_btn_url | string | Yes | None | This 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. |
payload | string | Yes | None | Some data. User ID, payment id, or any data you want to attach to the invoice. |
allow_comments | boolean | Yes | true | Allow adding comments when paying an invoice. |
allow_anonymous | boolean | Yes | true | Allow pay invoice as anonymous |
These are the parameters contained in a response of your request.
Name | Type | Description |
---|---|---|
app_id | string | |
name | string | |
payment_processing_bot_username | string |
Supported assets are
BTC, TON, ETH (only testnet), USDT, USDC, BUSD.
Name | Type | Description |
---|---|---|
currency_code | string | |
available | string |
Name | Type | Description |
---|---|---|
is_blockchain | boolean | |
is_stablecoin | boolean | |
is_fiat | boolean | |
name | string | |
code | string | |
url | string | |
decimals | number |
Name | Type | Description |
---|---|---|
is_valid | boolean | |
source | string | |
target | string | |
rate | string |
Name | Type | Description |
---|---|---|
count | number | |
items | Array of CryptoBotInvoice |
Name | Type | Description |
---|---|---|
count | number | |
items | Array of CryptoBotPayment |
Name | Type | Description |
---|---|---|
invoice_id | number | |
status | string | |
hash | string | |
asset | CryptoBotAsset | |
amount | string | |
pay_url | string | |
created_at | string | |
allow_comments | boolean | |
allow_anonymous | boolean | |
is_confirmed | boolean |
Name | Type | Description |
---|---|---|
invoice_id | number | |
status | string | |
hash | string | |
asset | CryptoBotAsset | |
amount | string | |
pay_url | string | |
created_at | string | |
paid_at | string | |
allow_comments | boolean | |
allow_anonymous | boolean | |
is_confirmed | boolean | |
confirmed_at | string or undefined | Won't be available in array of getPayments() |
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.