Coder Social home page Coder Social logo

iotap's Introduction

IOTAp

Promisify iota.lib.js API functions

Install

npm install --save iota.lib.js iotap

Changelog

  • 2.0.0 You should now use either .create or .invoke.

Full example usage

// This example gets the balance of two accounts
// and assumes you're passing in info about your
// IOTA node and the wallets/accounts via
// environment variables or https://npm.im/dotenv

// This example uses es6 modules so you'll need
// babel or @std/esm or you can use require instead
import IOTA from 'iota.lib.js';
import iotap from 'iotap';

const {
  IOTA_SOURCE_SEED,
  IOTA_PROTOCOL,
  IOTA_HOST,
  IOTA_PORT,
  IOTA_DESTINATION_ADDRESS,
  IOTA_DESTINATION_SEED
} = process.env;

console.log(`Using node ${IOTA_PROTOCOL}://${IOTA_HOST}:${IOTA_PORT}`)

// Connect to an IOTA instance
const iota = new IOTA({
    'host': `${IOTA_PROTOCOL}://${IOTA_HOST}`,
    'port': IOTA_PORT
});

// Pass in the instance of iota to iotap

// You can either create an instance
const i = iotap.create(iota);
const getSourceBalance = i.getAccountData(IOTA_SOURCE_SEED)
const getDestinationBalance = i.getAccountData(IOTA_DESTINATION_SEED);

// --- OR invoke ---
const getSourceBalance = iotap.invoke(iota, 'getAccountData')(IOTA_SOURCE_SEED);
const getDestinationBalance = iotap.invoke(iota, 'getAccountData')(IOTA_DESTINATION_SEED);

// The result will be a promise that you can use
// as you'd expect. This example uses Promise.all
// but you could just use .then if dealing with a single
// promise.
Promise.all([getSourceBalance, getDestinationBalance])
  .then(([sourceAccountData, destinationAccountData]) => console.log(sourceAccountData.balance, destinationAccountData.balance))
  .catch(e => console.error(e));

Donate IOTA

IOTA: NUCHQLPEBTDAKRCKEYLGQQNIYIKLKCBBNQWSAURCXQDDKSTXBCWZCPRCGRTSG9UHTCSNLGENX99DVFMMZJUEQSKEQ9

Donate IOTA

iotap's People

Contributors

jimthedev avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.