Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gactive = false
- local w = require("w") -- allows interaction with krist websocket api (for realtime data)
- local r = require("r") -- makes http requests easier
- local k = require("k") -- the krist api itself
- local jua = require("jua") -- makes events easier
- os.loadAPI("json.lua") -- to parse data returned by the krist api
- local await = jua.await
- r.init(jua)
- w.init(jua)
- k.init(jua, json, w, r)
- local function openWebsocket()
- local success, ws = await(k.connect, k.toKristWalletFormat(6798332999))
- assert(success, "Failed to get websocket URL")
- -- print("Connected to websocket.")
- -- here we subscribe to the 'transactions' event
- local success = await(ws.subscribe, "transactions", function(data)
- -- this function is called every time a transaction is made
- local transaction = data.transaction
- gactive = true
- --print("Transaction made:")
- --print("From: " .. transaction.from)
- --print("To: " .. transaction.to)
- --print("Value: " .. transaction.value .. " KST")
- -- Transactions have other properties, including "metadata", "id" and "time".
- -- Metadata can be parsed using k.parseMeta
- end)
- assert(success, "Failed to subscribe to event")
- end
- jua.go(function()
- openWebsocket()
- setInterval(main,0.001)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement