The AVA Platform Tools — Pt. 3, Slopes, Putting the AVA in jAVAscript

Collin Cusce
Mar 11 · 4 min read

Overview

The AVA Platform provides a Javascript library for interacting with AVA Platform APIs. It allows a developer to send to APIs, create assets, check balances, and send assets on the AVA Platform. It’s the foundational library behind the AVA Wallet and enables applications to easily integrate AVA into their workflow.

Why Slopes?

Slopes provides an ability that is found in the Gecko node itself: building and signing transactions. With the built-in keystore, one can load their private keys into the library, construct a raw transaction, and issue the transaction to any AVA node. With a signed transaction in-hand, applications built on AVA do not depend on the node for trusted signing. With Slopes we sign locally and send safely.

Additionally, Slopes offers the user a full set of updated API calls for interacting with an AVA node. This code will be kept in-line with AVA and should provide helpers to abstract away many of the details behind the AVA Platform. Full documentation of Slopes can be found on the documentation website: https://docs.ava.network.

Requirements

Slopes requires Node.js LTS version 12.13.1 or higher to compile.

Slopes depends on the following two Node.js modules internally, and we suggest that projects use them as well:

Buffer: Enables Node.js’s Buffer library in the browser.

BN.js: A big-number library for Node.js and browser.

Both of the above modules are extremely useful when interacting with Slopes as they are the input and output types of many base classes in the library.

Installing Slopes

Slopes is compatible with both Javascript and Typescript. It runs in both Node.js environments as well as reasonably modern browsers. It is provided as a handy npm package. To put Slopes into projects, simply run:

npm install slopes --save

This includes slopes into existing project’s node modules. Alternatively, Slopes can be built and included as a standalone Javascript file. To build Slopes, run:

This generates a “dist” directory with a “slopes.js” file that can be imported through an HTML script tag.

The Slopes API is quite comprehensive and is fully documented on https://docs.ava.network . There we’ll find examples of importing Slopes in projects, managing private keys using Slopes, creating assets, and sending transactions.

Building Applications With Slopes

Writing applications with Slopes is straightforward. Slopes is imported into a project, we create an instance of the Slopes class object, and we are now enabled to build transaction and call the Gecko API. Slopes tracks closely with the Gecko API and provides helper functions for managing the regular tasks involved with building on the AVA Platform.

Importing the Essentials

To import Slopes and the libraries it depends on, we place this on the top of Node.js code:

import * as slopes from "slopes";
import BN from 'bn.js';
import { Buffer } from 'buffer/';
let bintools = slopes.BinTools.getInstance();

The above lines import the libraries used in the below example:

  • slopes: AVA’s Javascript module.

A Brief Tour

Slopes has four top-level API’s exposed:

  • Admin — Sends to the the Admin API endpoint on an AVA node.

The API in Slopes mirrors the API on the node in a Javascript context. For example, to call the admin.peers() on the AVA node, in Slopes write:

//default is 2, we want to override that for a local network
let mynetworkID = 12345;
let ava = new slopes.Slopes("localhost", 9650, "https", mynetworkID);
let admin = ava.Admin(); // returns Admin API
let peers = admin.peers(); // returns Promise for list of peers

All of the remote API calls returns a Promise which returns a result once the AVA node response to the request.

A full list of both AVA node API calls and Slopes functionality is available on the documentation site: https://docs.ava.network.

The Journey Is Just Beginning

The AVA community has an exciting set of features to unveil over the next several releases. We are constantly innovating and building better tool suites to accommodate developers. Keep an eye on social media to hear the latest news about the AVA Platform. Hop into the Discord and introduce yourself to get involved. There’s other developers there to answer questions anyone has about the AVA Platform.

Stay tuned in, there’s a lot to come!



AVA Labs

AVA: Platform for DApps, Payments, Smart Assets, And Much More.

Collin Cusce

Written by

I work at AVA Labs. You should, too. It’s pretty awesome.

AVA Labs

AVA Labs

AVA: Platform for DApps, Payments, Smart Assets, And Much More.

More From Medium

More on Decentralization from AVA Labs

More on Decentralization from AVA Labs

How to Install and Run AVA — Borealis Release

Collin Cusce
Mar 11 · 7 min read

1.2K

More on Blockchain from AVA Labs

Collin Cusce
Mar 11 · 4 min read

98

More on Blockchain from AVA Labs

Collin Cusce
Mar 11 · 5 min read

95

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade