How to use the @iota/core.composeAPI function in @iota/core

To help you get started, we’ve selected a few @iota/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iotaledger / industry-marketplace / MaMa / wallet.js View on Github external
const { composeAPI } = require('@iota/core');
const { generateSeed } = require('./helpers');

// Create a new instance of the IOTA object
// Use the `provider` field to specify which IRI node to connect to
const provider = 'https://nodes.devnet.iota.org:443';
const iota = composeAPI({ provider });

const seed = generateSeed();

iota.getNewAddress(seed)
    .then(address => console.log(`Address: ${address} \nSeed: ${seed}`))
    .catch(err => console.log(err));

// Insert public adress into https://data.iota.org/#/faucet to get IOTA tokens
github iota-community / javascript-iota-workshop / code / 2.2-fetch-hello.js View on Github external
///////////////////////////////
// Fetch your HELLOWORLD Message
///////////////////////////////

const iotaLibrary = require('@iota/core')

const iota = iotaLibrary.composeAPI({
  provider: 'https://nodes.devnet.thetangle.org:443'
})

const address =
  'HEQLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWOR99DMNFAQLWHD'

iota
  .findTransactionObjects({ addresses: [address] })
  .then(response => {
    console.log(response)
  })
  .catch(err => {
    console.error(err)
  })
github iotaledger / industry-marketplace / MaMa / ServiceRequest.js View on Github external
const { composeAPI } = require('@iota/core');
const WebSocket = require('ws');
const zmq = require('zeromq');
const { sendMessage } = require('./Functions.js');

const sock = zmq.socket('sub');

// Create a new instance of the IOTA object
// Use the `provider` field to specify which IRI node to connect to
const provider = 'https://nodes.devnet.iota.org:443';

const iota = composeAPI({ provider });

//var ws = new WebSocket("ws://10.197.0.135:1880/ws/cfp")
const ws = new WebSocket('ws://127.0.0.1:1880/ws/sr');

ws.onopen = () => {
    console.log('CONNECTED');
};

const role = 'sr';
// Get json from websocket
ws.onmessage = msg => {
    functions.sendMessage(msg.data);
};
github iotaledger / industry-marketplace / MaMa / Functions.js View on Github external
const { composeAPI } = require('@iota/core');
const { asciiToTrytes } = require('@iota/converter');
const zmq = require('zeromq');
const WebSocket = require('ws');
const { decodeMessage, getLetterFromNumber, getCodeFromMessageType } = require('./helpers');


const sock = zmq.socket('sub');

const provider = 'https://nodes.devnet.iota.org:443';

//var ws = new WebSocket("wss://echo.websocket.org");
//var ws = new WebSocket("ws://127.0.0.1:1880/ws/sp")

const iota = composeAPI({ provider });

exports.fetchFromTangle = data => {
    return new Promise((resolve, reject) => {
        // Get bundle and extract data
        const bundle = data[8];

        iota.findTransactionObjects({ bundles: [bundle] })
            .then(transactionObject => {
                const msg = decodeMessage(transactionObject);
                resolve(msg);
            })
            .catch(err => {
                console.error(err);
                reject(err);
            });
    });
github iota-community / javascript-iota-workshop / code / 4-send-tokens.js View on Github external
///////////////////////////////
// Send tokens
///////////////////////////////

const iotaLibrary = require('@iota/core')

const iota = iotaLibrary.composeAPI({
  provider: 'https://nodes.devnet.thetangle.org:443'
})

// Replace this with the seed you sent tokens too!
const seed =
  'HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORL9D'

// Create a wrapping function so we can use async/await
const main = async () => {
  // Generate a different address from your seed
  const receivingAddress = await iota.getNewAddress(seed, {
    index: 1,
    total: 1
  })

  // Construct a TX to our new address
github iota-community / javascript-iota-workshop / code / 5.1-send-data.js View on Github external
///////////////////////////////
// Send Data
///////////////////////////////

const iotaLibrary = require('@iota/core')
const Converter = require('@iota/converter')

const iota = iotaLibrary.composeAPI({
  provider: 'https://nodes.devnet.thetangle.org:443'
})

// Use a random seed as there is no tokens being sent.
const seed =
  'PUEOTSEITFEVEWCWBTSIZM9NKRGJEIMXTULBACGFRQK9IMGICLBKW9TTEVSDQMGWKBXPVCBMMCXWMNPDX'

// Create a variable for the address we will send too
const address =
  'LOREMOORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLQD'

const message = Converter.asciiToTrytes(
  `IOTA WorkshopLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Vitae ultricies leo integer malesuada nunc vel risus commodo viverra. Risus in hendrerit gravida rutrum quisque. Scelerisque eu ultrices vitae auctor eu augue ut lectus arcu. Amet porttitor eget dolor morbi non. Fringilla phasellus faucibus scelerisque eleifend donec pretium vulputate sapien. A diam sollicitudin tempor id eu nisl nunc. Sit amet consectetur adipiscing elit duis. Et netus et malesuada fames ac turpis egestas sed. Volutpat sed cras ornare arcu. Id porta nibh venenatis cras sed. Vulputate enim nulla aliquet porttitor lacus luctus. Turpis egestas pretium aenean pharetra magna ac placerat. Neque aliquam vestibulum morbi blandit cursus risus at ultrices mi.Arcu odio ut sem nulla pharetra diam. Tellus id interdum velit laoreet id. Odio ut sem nulla pharetra diam. Curabitur vitae nunc sed velit dignissim sodales ut eu sem. Pharetra pharetra massa massa ultricies. Lectus urna duis convallis convallis tellus id interdum velit laoreet. Quam adipiscing vitae proin sagittis nisl rhoncus. Lacus suspendisse faucibus interdum posuere lorem ipsum dolor. Felis eget nunc lobortis mattis aliquam faucibus purus. Interdum velit laoreet id donec ultrices tincidunt. In fermentum posuere urna nec tincidunt. Tortor aliquam nulla facilisi cras fermentum odio eu. Imperdiet nulla malesuada pellentesque elit eget gravida cum sociis.Dignissim sodales ut eu sem integer vitae justo eget magna. Aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed. Eget mi proin sed libero enim sed faucibus turpis in. Neque gravida in fermentum et. Diam quam nulla porttitor massa. A lacus vestibulum sed arcu non odio euismod lacinia at. Sed nisi lacus sed viverra tellus in hac habitasse platea. Enim lobortis scelerisque fermentum dui. Lorem dolor sed viverra ipsum nunc aliquet `
)

const transfers = [
github iota-community / javascript-iota-workshop / code / detailed transaction creation.js View on Github external
///////////////////////////////
// Detailed transaction creation
///////////////////////////////

const iotaLibrary = require('@iota/core')
const txconverter = require('@iota/transaction-converter')

const iota = iotaLibrary.composeAPI({
  provider: 'https://nodes.devnet.thetangle.org:443'
})

const seed =
  'PUEOTSEITFEVEWCWBTSIZM9NKRGJEIMXTULBACGFRQK9IMGICLBKW9TTEVSDQMGWKBXPVCBMMCXWMNPDX'
const address =
  'HELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLQD'
const transfers = [
  {
    value: 0,
    address: address,
    tag: 'XXAAXXAA9XX'
  }
]

// Create a wrapping function so we can use async/await
github iota-community / javascript-iota-workshop / code / 2.1-send-hello.js View on Github external
///////////////////////////////
// Send HELLOWORLD
///////////////////////////////

const iotaLibrary = require('@iota/core')

const iota = iotaLibrary.composeAPI({
  provider: 'https://nodes.devnet.thetangle.org:443'
})

const address =
  'HEQLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWORLDHELLOWOR99D'
const seed =
  'PUEOTSEITFEVEWCWBTSIZM9NKRGJEIMXTULBACGFRQK9IMGICLBKW9TTEVSDQMGWKBXPVCBMMCXWMNPDX'

const transfers = [
  {
    value: 0,
    address: address,
    tag: 'KLULTWYK9FP'
  }
]
github iotaledger / industry-marketplace / MaMa / SendMessage.js View on Github external
const { composeAPI } = require('@iota/core');
const { asciiToTrytes } = require('@iota/converter');
const zmq = require('zeromq');
const WebSocket = require('ws');
const { sendToUI, sendToTangle } = require('./Functions.js');

//var ws = new WebSocket("wss://echo.websocket.org");
//var ws = new WebSocket("ws://127.0.0.1:1880/ws/sp")

const sock = zmq.socket('sub');

const provider = 'https://nodes.devnet.iota.org:443';

const iota = composeAPI({ provider });

exports.sendMessage = data => {
    const json = JSON.parse(data);

    //Extract Dienstleistungs ID and Type of Message
    const type = json.frame.type;
    const serviceID = json.dataElements.submodels[0].identification.id;

    //Remove #, -, version number from Dienstleistungs ID to build tag
    //Convert tag to Trytes to be suitable for Tag (Allowed: 'A-Z & 9')
    const abbrServiceID = serviceID.replace(/#/g, '').replace(/-/g, '');
    let tag = abbrServiceID.substr(0, abbrServiceID.length - 3);
    tag = asciiToTrytes(tag);

    if (type === 'callForProposal') {
        sendToTangle(data, tag);
github allemanfredi / PEGASUS / packages / background / controllers / wallet-controller.js View on Github external
async addAccount (account, isCurrent) {

    if (isCurrent) {
      const data = this.storageController.getData()
      data.forEach(acc => { acc.current = false })
      this.storageController.setData(data)
    }

    const network = this.networkController.getCurrentNetwork()
    const iota = composeAPI({ provider: network.provider })
    const seed = account.seed.toString().replace(/,/g, '')
    const accountData = await iota.getAccountData(seed,
       { start: 0, security: 2 }
    )

    accountData.balance = {
      testnet: 0,
      mainnet: 0
    }

    const key = this.getKey()
    const eseed = Utils.aes256encrypt(seed, key)

    const accountToAdd = {
      name: account.name,
      avatar: account.avatar,