The Upvest Blockchain API

A multi-protocol blockchain API for building blockchain-interacting applications.

Get Started     Tutorial     API Reference

Setup for the Tutorial

This setup allows you to complete the tutorial using an editor of your choice. Here are the steps to follow:

  1. Make sure you have a recent version of Node.js installed.
  2. Make a new directory to host the project and create a package.json file.
mkdir upvest-tutorial
cd upvest-tutorial
npm init --yes
  1. Add a couple of dependencies to the package.json file. In the tutorial, we will use axios as our HTTP client to make and handle HTTP requests. We will use the dotenv package to conveniently load environment variables. In order to easily parse arguments from the command line, we will use the minimist module.
npm add axios dotenv minimist
  1. Make a .env file to host environment variables for our app.
touch .env
  1. Enter the following code in the newly created .env file:
API_BASE_URL=https://api.playground.upvest.co
API_VERSION=1.0

# Set your tenancy API key information here.
API_KEY=
API_SECRET=
API_PASSPHRASE=

# Set your OAuth2 client information here.
OAUTH2_CLIENT_ID=
OAUTH2_CLIENT_SECRET=
  1. Make an src/ directory with a config.js file.
mkdir src
touch src/config.js
  1. Enter the following code in the newly created config.js file:
const dotenv = require("dotenv");

// Read environment variables from the `.env` file.
dotenv.config();

// Expose consolidated environment variables.
module.exports = {
  API_BASE_URL: process.env.API_BASE_URL,
  API_VERSION: process.env.API_VERSION,
  API_KEY: process.env.API_KEY,
  API_SECRET: process.env.API_SECRET,
  API_PASSPHRASE: process.env.API_PASSPHRASE,
  OAUTH2_CLIENT_ID: process.env.OAUTH2_CLIENT_ID,
  OAUTH2_CLIENT_SECRET: process.env.OAUTH2_CLIENT_SECRET
};
  1. Make an index.js file.
touch src/index.js
  1. Enter the following code in the newly created index.js file:
const { API_VERSION } = require("./config");

// Import argument options parser.
const minimist = require("minimist");

const INTERPRETER_AND_FILE_ARGS_LENGTH = 2;

const ECHO_MESSAGE_CMD = "echo";

module.exports = () => {
  /* Remove the first arguments because the first argument will always be the
   * interpreter followed by the name of the file being interpreted. We only
   * care about the arguments after that.
   */
  const args = minimist(process.argv.slice(INTERPRETER_AND_FILE_ARGS_LENGTH));
  // Our first argument is now our command.
  const command = args._[0];

  // Act on the command issued.
  switch (command) {
    case ECHO_MESSAGE_CMD: {
      console.log(`Hello, Upvest API v${API_VERSION}!`);
      break;
    }
    default: {
      console.error(`"${command}" is not a valid command!`);
      break;
    }
  }
};
  1. Make a bin/ directory with an executable upvest file.
mkdir bin
touch bin/upvest
chmod +x bin/upvest
  1. Enter the following code in the newly created upvest file:
#!/usr/bin/env node

require("../src/")();
  1. Now, if you run bin/upvest echo in the project directory, you should see the output Hello, Upvest v1.0!

Updated about a year ago


What's Next

Fundamentals

Setup for the Tutorial


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.