Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require("fs");
const { createPrepareTransfers, generateAddress } = require('@iota/core');
const { asTransactionObject } = require("@iota/transaction-converter");
const NUM_BUNDLES = 100;
const MAX_BUNDLE_SIZE = 10;
// prepare transfers offline
const prepareTransfers = createPrepareTransfers(undefined, Date.now());
function randomInt(min, max, excluding) {
let value;
do {
value = Math.floor(Math.random() * (max - min + 1)) + min;
} while (excluding.includes(value));
return value;
}
function randomTrytes(length) {
const possible = "NOPQRSTUVWXYZ9ABCDEFGHIJKLM";
let text = "";
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
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
///////////////////////////////
// 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)
})
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);
};
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);
});
});
///////////////////////////////
// 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
///////////////////////////////
// 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 = [
///////////////////////////////
// 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
///////////////////////////////
// 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'
}
]
return new Promise((resolve, reject) => {
const remainderAddress = generateAddress(seed, keyIndex + 1);
const options = {
inputs: [{
address,
keyIndex,
security,
balance
}],
security,
remainderAddress
};
prepareTransfers(seed, transfers, options)
.then(async trytes => {
sendTrytes(trytes, depth, minWeightMagnitude)
.then(async transactions => {
// Before the payment is confirmed update the wallet with new address and index, calculate expected balance