Socket
Socket
Sign inDemoInstall

@discoin/scambio

Package Overview
Dependencies
25
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @discoin/scambio

[![npm version](https://img.shields.io/npm/v/@discoin/scambio)](https://www.npmjs.com/package/@discoin/scambio) [![codecov](https://codecov.io/gh/Discoin/scambio/branch/merge/graph/badge.svg)](https://codecov.io/gh/Discoin/scambio) [![MIT license](https:/


Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Install size
583 kB
Created
Weekly downloads
 

Readme

Source

@discoin/scambio

npm version codecov MIT license Build Status XO code style DeepScan grade

The official JS/TS library for Discoin. Features browser and first-class TypeScript support.

Usage

Install

yarn add @discoin/scambio

# Or for npm

npm i @discoin/scambio

# Or for pnpm

pnpm i @discoin/scambio

If you want to do more complex queries you may want to use the @nestjsx/crud-request package, which is specifically designed for the Discoin API. Most users won't need it but it is listed as a peer dependency. You can safely ignore any warnings about it if you aren't using it.

Examples

Below are several examples of how you can use the library. You do everything through a client instance or its static members.

Creating a new client
ECMAScript modules
import Discoin from '@discoin/scambio';

const client = new Discoin('token', ['currencyCode']);
CommonJS
const Discoin = require('@discoin/scambio').default;

const client = new Discoin('token', ['currencyCode']);
Creating a transaction
const newTransaction = client.transactions.create({
	from: 'XYZ',
	to: 'ABC',
	amount: 100,
	// Discord user ID
	user: '210024244766179329'
});
Getting transactions
Get one transaction by ID
await client.transactions.getOne('808179ef-aef4-4bbb-ab37-db310235fb0c');
Get many transactions with built-in queries

This uses common queries, which are generated specifically for your client and don't need any extra dependencies.

await client.transactions.getMany(client.commonQueries.UNHANDLED_TRANSACTIONS);
Get many transactions with query builder

This uses the @nestjsx/crud-request query builder. You should use this when you are performing very complex queries or are dynamically creating queries.

import {RequestQueryBuilder, CondOperator} from '@nestjsx/crud-request';

const query = RequestQueryBuilder.create()
	// Only get transactions where the `amount` field > 10
	.setFilter({
		field: 'amount',
		operator: CondOperator.GREATER_THAN,
		value: 10
	})
	.query();

await client.transactions.getMany(query);
Processing transactions

You can mark a transaction as handled after you have paid the user. This helps to keep transactions atomic and can make retrying failed transactions very simple.

const unhandledTransactions = await client.transactions.getMany(client.commonQueries.UNHANDLED_TRANSACTIONS);

unhandledTransactions.forEach(async transaction => {
	console.log(`${transaction.user} received ${transaction.payout} ${transaction.to.id}`);

	// After you're done with the transaction, mark it as completed
	await transaction.update({handled: true});
});

Contributing

Pull requests and issues are always welcome! Please, read our Code of Conduct and our contributing guide if you are interested in helping to improve the library..

Licence

Copyright 2019-2020 Jonah Snider. Distributed under the MIT licence.

If you would like the licence to be something other than MIT for you or your organization please get in touch.

Keywords

FAQs

Last updated on 29 Dec 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc