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

@upvest/clientele-api

v0.0.29

Published

An axios-based, browser-runnable, client for the Upvest Clientele API

Downloads

51

Readme

Client library for the Upvest Clientele API

This API encompasses operations on behalf of your users, which are things like creating blockchain transactions (yet to be implemented) and inspecting wallet balances, etc.

This API client is based on axios.

Features

  • Get user wallets list
  • Create new wallet
  • Retrieve wallet data
  • Get assets list
  • Retrieve asset data
  • Get transactions list
  • Send transaction
  • Retrieve transaction data

Installation

Using yarn:

$ yarn add @upvest/clientele-api

Using npm:

$ npm install @upvest/clientele-api

In order to retrieve your API credentials for using this client, you'll need to sign up with Upvest.

OAuth Authentication

The authentication via OAuth allows you to perform operations on behalf of your user. For more information on the OAuth concept, please refer to our documentation. Again, please retrieve your client credentials from the Upvest account management.

const { UpvestClienteleAPI } = require("@upvest/clientele-api");

const USERNAME = "Example User";
const PASSWORD = "ex@mp1e p@55w0rd";

const config = {
  baseURL: "https://api-playground.eu.upvest.co/1.0/",
  oauth2: {
    client_id: CLIENT_ID,
    client_secret: CLIENT_SECRET
  }
};

Response objects

The response objects are designed around users, wallets, transactions and assets. If you retrieve more than one object (for example: clientele.wallets.list()) an array of those objects will be returned.

Wallet object

The wallet response object has the following properties:

let wallet = clientele.wallets.retrieve("wallet_id");
const { id, address, balances, protocol, status } = wallet;

Asset object

The transaction response object has the following properties:

let asset = clientele.assets.retrieve("asset_id");
const { id, name, symbol, exponent, protocol, metadata } = asset;

Transaction object

The transaction response object has the following properties:

let transaction = wallet.transactions.retrieve("transaction_id");
const {
  quantity,
  fee,
  recipient,
  sender,
  id,
  status,
  txhash,
  wallet_id,
  asset_id,
  asset_name,
  exponent
} = transaction;

Usage

Clientele

Create an UpvestClienteleAPI object with these credentials and your user authentication data in order to authenticate your API calls on behalf of a user:

const clientele = new UpvestClienteleAPI(
  config.baseURL,
  config.oauth2.client_id,
  config.oauth2.client_secret,
  USERNAME,
  PASSWORD
);

Assets

List available assets
(async () => {
  let assets = [];
  for await (let asset of this.clientele.assets.list()) assets.push(asset);
  console.log("Available assets: ", assets);
})();
Retrieve specific asset by asset_id
(async () => {
  try {
    const asset = await this.clientele.assets.retrieve(ASSET_ID);
    console.log("Asset: ", asset);
  } catch (_) {}
})();

Wallets

Get user wallets list
(async () => {
  let wallets = [];
  for await (const wallet of clientele.wallets.list()) {
    wallets.push(wallet);
  }
  console.log(wallets);
})();
Create new wallet
(async () => {
  try {
    let newWallet = await clientele.wallets.create(ASSET_ID, PASSWORD);
    console.log(newWallet);
  } catch (_) {}
})();
Retrieve specific wallet for a user
(async () => {
  try {
    let wallet = await clientele.wallets.retrieve(WALLET_ID);
    console.log(wallet);
  } catch (_) {}
})();

Transactions

Create transaction
(async () => {
  try {
    const AMOUNT = 100000000000000000; // 0.1 ETH * 10^18 = 100000000000000000 WEI
    const FEE = 4000000000000000; // 0.004 ETH * 10^18 = 4000000000000000 WEI

    // Send the transaction
    const RECIPIENT = "0x05b3Ca5e520583e3BBfb4DdDf5bd212CB19b2169";
    const transaction = await clientele.transactions.create(
      WALLET_ID,
      PASSWORD,
      RECIPIENT,
      ASSET_ID,
      AMOUNT,
      FEE
    );
    const transactionHash = transaction.txhash;
    console.log(transaction);
    console.log(`https://ropsten.etherscan.io/tx/${transactionHash}`);
  } catch (_) {}
})();
List all transactions of a wallet for a user
(async () => {
  let transactions = [];
  for await (let transaction of this.clientele.transactions.list(WALLET_ID))
    transactions.push(transaction);
  console.log("Transactions: ", transactions);
})();
Retrieve specific transaction
(async () => {
  try {
    let transaction = await this.clientele.transactions.retrieve(
      WALLET_ID,
      TRANSACTION_ID
    );
    console.log("Transaction: ", transaction);
  } catch (_) {}
})();

For more examples, please check out our test-suite at https://www.npmjs.com/package/@upvest/api-tests

License

This software is released under the MIT License