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

azimuth-js

v0.23.0

Published

Functions for interacting with Azimuth

Downloads

209

Readme

azimuth-js

Build Status MIT License npm

Interact with Azimuth from Javascript.

Install

Just grab from npm like so:

npm install azimuth-js

API Reference

./docs/

Quickstart

(This example uses an Infura endpoint as a provider for web3.)

const ajs = require('azimuth-js')
const Web3 = require('web3')

const infura   = `https://mainnet.infura.io/v3/${MY_INFURA_ID}`
const provider = new Web3.providers.HttpProvider(infura)
const web3     = new Web3(provider)

const contracts = await ajs.initContractsPartial(web3, ajs.azimuth.mainnet)

const zod = '0x9F57C77b1095BD5Db0558b9Cb9b8e6Fc67375E3C'

ajs.azimuth.isOwner(contracts, 0, zod).then(console.log) // true

Usage

Require the library via something like:

const azimuthjs = require('azimuth-js');

In general: use the functions in azimuthjs.ecliptic, azimuthjs.azimuth, azimuthjs.polls, and so on to interact with the corresponding Ethereum contract. Use azimuthjs.check to verify any required state is what you expect it to be. azimuthjs.txn contains functions for signing and sending transactions, and azimuthjs.utils mostly re-exports useful utility functions from ethereumjs-util.

You might want to define something like the following, for convenience:

const ecliptic = azimuthjs.ecliptic;
const azimuth = azimuthjs.azimuth;
const check = azimuthjs.check;
const txn = azimuthjs.txn

The library exposes a purely-functional API. This means you'll have to supply your own state (e.g. web3 instance, contracts instance) whenever dealing with transactions and contract initialisation. For example, when running a fresh local Ganache node with the appropriate mnemonic (see below), this will get you set up:

const Web3 = require('web3');

let provider = new Web3.providers.HttpProvider('http://localhost:8545');
let web3 = new Web3(provider);

let contractAddresses = {
    ecliptic: '0x56db68f29203ff44a803faa2404a44ecbb7a7480',
    azimuth:  '0x863d9c2e5c4c133596cfac29d55255f0d0f86381',
    polls:    '0x935452c45eda2958976a429c9733c40302995efd',
    claims:   '0xe0834579269eac6beca2882a6a21f6fb0b1d7196'
  }

let contracts = azimuthjs.initContracts(web3, contractAddresses);

Note that the web3 object is passed to azimuthjs.initContracts explicitly. Aside from contract initialisation, this is typically only required when sending transactions (more below).

When interacting with the contract APIs, on the other hand, you'll almost always have to pass a contracts object explicitly. For example:

// ecliptic owner
const owner = '0x6deffb0cafdb11d175f123f6891aa64f01c24f7d';

const galaxy = 42;

check.canCreateGalaxy(contracts, galaxy, owner);

Note that the 'contracts' object initialised previously is passed as the first argument. Again, this is almost always the case.

Most of the exposed contracts API consists of functions that, at most, read from the Ethereum chain state, returning some result in a Promise. The primary exceptions are some of the functions in the 'ecliptic' contract; for those that modify chain state, the function will return a transaction object, e.g.:

let tx = ecliptic.createGalaxy(contracts, galaxy, owner);

To modify contract state, you'll have to sign ('signTransaction') and send ('sendSignedTransaction') the transaction explicitly. For example:

txn.signTransaction(web3, tx, pk).then(stx =>
  txn.sendSignedTransaction(web3, stx));

or, in the body of an async function, you can use await:

let stx = await txn.signTransaction(web3, tx, pk);
txn.sendSignedTransaction(web3, stx);

Note again that, when dealing with transactions, a web3 object must be passed as the first argument.

Many of the functions for the 'azimuth' contract will work when the function is passed either a point identifier (i.e. an unsigned integer), meaning the computation will be carried out on-chain, or a point object (i.e. something that has been retrieved via 'azimuth.getPoint'), meaning the computation will be carried out purely, simply by reference to the point object. The result is wrapped in a Promise, in either case.

Functions that use Web3 may throw. The thrown object will always contain at least 'name' and 'message' properties. Tread carefully when using Web3 while offline.

Contract action checks ('canXYZ') return result objects in the form of { result: bool, reason: string }, where 'reason' is only set when 'result' is 'false'. These can't resolve when offline.

Development

Library Structure

The modules found in the internal directory are intended to be fairly close mappings to the public, external, or view functions located in the contracts themselves. Mostly these are re-exported via the user-facing API, defined in ecliptic.js and friends.

The one notable exception is in the azimuth module, where the behaviour of a function can often depend on the type of the argument passed to it. If one passes them a cached point object (retrieved via getPoint), then these functions will compute their values locally; if one supplies them with a point number (i.e., an integer), they will instead hit the network.

Testing

Use a simple:

npm test

to run the tests on a one-off local Ganache node.

Local Testnet

For debugging and custom testing, you'll need a local testnet running Azimuth.

  1. Clone Azimuth
  2. cd into the repo and npm install
  3. npm install -g ganache-cli
  4. Run a local ganache node, boot using the following command to ensure a matching seed: ganache-cli -m "benefit crew supreme gesture quantum web media hazard theory mercy wing kitten"
  5. Run truffle deploy from the Azimuth directory to deploy to your local node.