IOTA Client Reference Implementation in Javascript
Install using npm:
npm install @iota/core
or using yarn:
yarn add @iota/core
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:
- Install an IRI http client:
npm install @iota/http-client
- 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)
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
iota.prepareTransfers(seed, transfers)
.then(trytes => 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
})
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.
We thank everyone for their contributions. Here is quick guide to get started with iota.js monorepo:
- Fork the repo with Fork button at top right corner.
- Clone your fork locally and
cd
in it. - 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.
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.
Please update the documention when needed by editing JSDoc
annotations and running npm run docs
from the root directory.
Please report any problems you encouter during development by opening an issue.
Suggestions and discussion around specs, standardization and enhancements are highly encouraged. You are invited to join the discussion on IOTA Discord.