Giter Site home page Giter Site logo

hw-app-iota.js's Introduction

hw-app-iota

GitHub License NPM Version Actions Status

JS Library for communication with Ledger Hardware Wallets and the IOTA Ledger Application.

Examples

Basic example

import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Iota from 'hw-app-iota';

const getAddress = async () => {
  const transport = await Transport.create();
  const iota = new Iota(transport);
  await iota.setActiveSeed("44'/4218'/0'/0'");
  return await iota.getAddress(0, {checksum: true});
};

getAddress().then(a => console.log(a));

Transaction example

import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Iota from 'hw-app-iota';

const prepareTransfers = async () => {
  const transport = await Transport.create();
  const iota = new Iota(transport);
  await iota.setActiveSeed("44'/4218'/0'/0'");

  const transfers = [{
    address: 'ANADDRESS',
    value: 10000,
    tag: 'ATAG'
  }];
  const inputs = [{
    address: 'INPUTADDRESS',
    balance: 10000,
    keyIndex: 4
  }];
  return await iota.prepareTransfers(transfers, inputs);
};

prepareTransfers().then(t => console.log(t));

See also

API Reference

hw-app-iota~Iota

Class for the interaction with the Ledger IOTA application.

iota.setActiveSeed(path, [security])

Prepares the IOTA seed to be used for subsequent calls.

Param Type Default Description
path String String representation of the BIP32 path. At most 5 levels.
[security] Integer 2 IOTA security level to use

Example

iota.setActiveSeed("44'/4218'/0'/0'", 2);

iota.getAddress(index, [options]) ⇒ Promise.<String>

Generates an address index-based. The result depends on the initalized seed and security level.

Returns: Promise.<String> - Tryte-encoded address

Param Type Default Description
index Integer Index of the address
[options] Object
[options.checksum] Boolean false Append 9 tryte checksum
[options.display] Boolean false Display generated address on display

Example

iota.getAddress(0, { checksum: true });

iota.prepareTransfers(transfers, inputs, [remainder], [now]) ⇒ Promise.<Array.<String>>

Prepares the array of raw transaction data (trytes) by generating a bundle and signing the inputs.

Returns: Promise.<Array.<String>> - Transaction trytes of 2673 trytes per transaction

Param Type Default Description
transfers Array.<Object> Transfer objects
transfers[].address String Tryte-encoded address of recipient, with or without the 9 tryte checksum
transfers[].value Integer Value to be transferred
transfers[].tag String Tryte-encoded tag. Maximum value is 27 trytes.
inputs Array.<Object> Inputs used for funding the transfer
inputs[].address String Tryte-encoded source address, with or without the 9 tryte checksum
inputs[].balance Integer Balance of that input
inputs[].keyIndex String Index of the address
[inputs[].tags] Array.<String> Tryte-encoded tags, one for each security level.
[remainder] Object Destination for sending the remainder value (of the inputs) to.
remainder.address String Tryte-encoded address, with or without the 9 tryte checksum
remainder.keyIndex Integer Index of the address
[remainder.tag] String Tryte-encoded tag. Maximum value is 27 trytes.
[now] function Date.now() Function to get the milliseconds since the UNIX epoch for timestamps.

iota.getAppVersion() ⇒ Promise.<String>

Retrieves version information about the installed application from the device.

Returns: Promise.<String> - Semantic Version string (i.e. MAJOR.MINOR.PATCH)

iota.getAppMaxBundleSize() ⇒ Promise.<Integer>

Retrieves the largest supported number of transactions (including meta transactions) in one transfer bundle from the device.

Returns: Promise.<Integer> - Maximum bundle size

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.