wilsonfonseca / iota.js

IOTA JavaScript monorepo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iota.js

IOTA Client Reference Implementation in Javascript

Build Status GitHub license Discord Greenkeeper badge


Getting started

Installation

Install using npm:

npm install @iota/core

or using yarn:

yarn add @iota/core

Connecting to network

import { composeAPI } from '@iota/core'

const iota = composeAPI({
    provider: 'http://localhost:14265'
})

iota.getNodeInfo()
    .then(info => console.log(info))
    .catch(err => {})

Composing custom client methods with network provider:

  1. Install an IRI http client:
npm install @iota/http-client
  1. Create an api method with custom provider:
import { createHttpClient } from '@iota/http-client'
import { createGetNodeInfo } from '@iota/core'

const client = createHttpClient({
    provider: 'http://localhost:14265'
})

const getNodeInfo = createGetNodeInfo(client)

Creating & broadcasting transactions

Publish transfers by calling prepareTransfers and piping the prepared trytes to sendTrytes command.

Feel free to use devnet and take advatage of PoWbox as well as IOTA faucet during development.

// must be truly random & 81-trytes long
const seed = ' your seed here '

// Array of transfers which defines transfer recipients and value transferred in IOTAs.
const transfers = [{
    address: ' recipient address here ',
    value: 1000, // 1Ki
    tag: '', // optional tag of `0-27` trytes
    message: '' // optional message in trytes
}]

// Depth or how far to go for tip selection entry point
const depth = 3 

// Difficulty of Proof-of-Work required to attach transaction to tangle.
// Minimum value on mainnet & spamnet is `14`, `9` on devnet and other testnets.
const minWeightMagnitude = 14

// Prepare a bundle and signs it
iota.prepareTransfers(seed, transfers)
    .then(trytes => {
        // Persist trytes locally before sending to network.
        // This allows for reattachments and prevents key reuse if trytes can't
        // be recovered by querying the network after broadcasting.

        // Does tip selection, attaches to tangle by doing PoW and broadcasts.
        return iota.sendTrytes(trytes, depth, minWeightMagnitude)
    })
    .then(bundle => {
        console.log(`Published transaction with tail hash: ${bundle[0].hash}`)
        console.log(`Bundle: ${bundle}`)
    })
    .catch(err => {
        // catch any errors
    })

Documentation

For details on all available API methods please see the reference page.

Documentation of IOTA protocol and IRI http API can be found on docs.iota.works.

Contributing

We thank everyone for their contributions. Here is quick guide to get started with iota.js monorepo:

Clone and bootstrap

  1. Fork the repo with Fork button at top right corner.
  2. Clone your fork locally and cd in it.
  3. Bootstrap your environment with:
npm run init

This will install all dependencies, build and link the packages together. iota.js uses Lerna to manage multiple packages. You can re-bootstrap your setup at any point with lerna bootstrap command.

Run the tests

Make your changes on a single or across multiple packages and test the system in integration. Run from the root directory:

npm test

To run tests of specific package just cd to the package directory and run npm test from there.

You may also want to configure your editor to build the source uppon save and watch the tests running. Once building on save is setup, you can start watching tests with npm test --watch from each package directory.

Updating documentation

Please update the documention when needed by editing JSDoc annotations and running npm run docs from the root directory.

Reporting Issues

Please report any problems you encouter during development by opening an issue.

Join the discussion

Suggestions and discussion around specs, standardization and enhancements are highly encouraged. You are invited to join the discussion on IOTA Discord.

About

IOTA JavaScript monorepo

License:MIT License


Languages

Language:TypeScript 96.3%Language:HTML 1.0%Language:JavaScript 0.8%Language:Objective-C 0.7%Language:Java 0.5%Language:Shell 0.3%Language:C 0.2%Language:Ruby 0.1%