This is a tutorial for beginners. If you know a thing or two about programming you can skip to Usage .
You need node.js to follow this tutorial. Please read the install instructions first
Create a directory for your project ...
mkdir ostdemo
cd ostdemo
... then initialize npm (just press enter at at all prompts)...
npm init
... and install the required packages.
npm install ostkit express --save
We need to write some JavaScript to work with ostkit.js. I recommend using Visual Studio Code for JavaScript, but you can use any editor you like.
We will interact with OSt KIT through a web interface. That's why we installed express. express makes it easy to write web applications with node.js.
Our first server will not do much ...
// app.js
const express = require('express')
const app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(3000, () => console.log('Example app listening on port 3000!'))
... run your server ...
node app.js
... you can now point your browser to http://localhost:3000 and see your first web application. Unfortunately it is very static. No information from OST KIT yet.
Your kit.ost.com console has a tab labeled Developers. You need to click on the "SHOW KEYS" Button to reveal your API credentials !!DO NOT SHARE YOUR SECRET WITH ANYONE!!.
Now update your app.js to look like this:
// app.js
const express = require('express')
const app = express()
const Ostkit = require("ostkit"); // tell node.js that you need ostkit.js
const ost=new Ostkit("YOUR_API_KEY", "YOUR_API_SECRET"); // initialize the API connection
app.get('/', (req, res) => { // when URL is the root of your server
ost.transactiontypesList().then((data) => { // call /transaction-types/list method and...
var result = "Your Token: "+data.client_tokens.name; // write client_tokens.name to "result"
res.send(result); // and return "result" to the browser
})
})
app.listen(3000, () => console.log('Example app listening on port 3000!'))
... restart node (press [CTRL]+[C] to stop it) ...
node app.js
and go to to http://localhost:3000 again.
Your Token: Reward Token (RWD)