-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimple_addition_example.js
34 lines (24 loc) · 1.18 KB
/
simple_addition_example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// This example simplify adds two numbers together, with tree inputs
// Swarm App: https://swarm.thorntontomasetti.com/app/5f998551dd6d710004c38ca4/info
var Swarm = require('@ttcorestudio/swarm');
var swarmApp = new Swarm.SwarmApp();
swarmApp.setDocument(8, 0.001); // Set Document unit and tolerance
swarmApp.logging = true;
swarmApp.appToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MzYyNTAwMDkzODIsImV4cCI6MTYzNjI1NTE5MzM4MiwicHJvamVjdElkIjoiNWY5OTg1NTFkZDZkNzEwMDA0YzM4Y2E0In0.43Nk21NG8PGA6PiJ_UF3pW7VPWHHqht1hQTEzTOfKYo";
// Declare inputs first
let input_A = new Swarm.Input("A", "Number");
let input_B = new Swarm.Input("B", "Number");
// Add values to inputs
input_A.addDataTree(0, [13, 14]);
input_A.addDataTree(1, 15);
input_B.addDataTree(0, [13,14]);
swarmApp.inputs.push(input_A);
swarmApp.inputs.push(input_B);
// Sending to Swarm for compute
swarmApp.compute().then(output => {
if (output == null) return console.log("No compute result came back.");
let val = output.outputs;
console.log("There are " + val.length + " inputs in this compute");
let outputA = output.outputs[0];
console.log("Output A has " + outputA.branches.length + " branches", outputA);
});