shopk v1.0.3

A Kromer cryptocurrency API client for ComputerCraft that provides real-time transaction monitoring and wallet operations through WebSocket connections. Features: Real-time transaction monitoring via WebSocket, automatic reconnection on connection loss, transaction sending with metadata support, wallet information retrieval, metadata parsing for structured data, and event-driven architecture.

Installation

Recommended: Install via installer (handles dependencies automatically):

wget run https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua shopk
View on GitHub →

This pattern downloads and runs libraries at runtime, automatically installing any that are missing:

Lua
-- Auto-install and require libraries
local libs = {"shopk"} -- Add more libraries as needed
local libDir = (fs.exists("disk") and "disk/lib/" or "/lib/")
local allExist = true

for _, lib in ipairs(libs) do
    if not fs.exists(libDir .. lib .. ".lua") then
        allExist = false
        break
    end
end

if not allExist then
    shell.run("wget", "run", "https://raw.githubusercontent.com/Twijn/cc-misc/main/util/installer.lua", table.unpack(libs))
end

local shopk = require(libDir .. "shopk")

-- Use the library
-- (your code here)

Alternative: Direct download via wget:

wget https://raw.githubusercontent.com/Twijn/cc-misc/main/util/shopk.lua

Examples

Lua
local shopk = require("shopk")

local client = shopk({
 privatekey = "testing123", -- keep this safe!
})

client.on("transaction", function(tx)
 --if tx.to ~= client.address.address then return end -- uncomment to only process incoming transactions to the connected wallet
 print(("%s -> %s : %.2f KRO"):format(tx.from, tx.to, tx.value))
 if tx.hasMeta("test") then -- checks if there is a standalone value of the string,
   -- i.e "unre=lated;test" would match but "unre=lated;test=ing" would not
   tx.refund(tx.value, "Refunding full amount for test metadata", function(data)
     if data.ok then
       print("Refund successful!")
     end
   end)
 end
end)

client.on("connected", function(isGuest, address)
 if isGuest then
   print("Connected! Logged in as guest.")
 else
   print(("Connected! Logged in as %s with %.2f KRO."):format(address.address, address.balance))
 end
end)

client.on("error", function(err)
 print(("Error [%s]: %s"):format(err.error, err.message))
end)

-- The client has errored or disconnected and is starting to reconnect
client.on("connecting", function()
 print("Connecting...")
end)

client.on("closed", function()
 print("Closed!")
end)

client.run()

Functions

module.on(event, listener)

View source on GitHub

Register an event listener Starting in 1.0.1, "ready" was renamed to "connected", and additional state management events have been added. "connected" now also calls with (isGuest: boolean, address: table?) when the connection is established.

Parameters:

module.run()

View source on GitHub

Start the WebSocket connection and enter the main event loop This function blocks until the connection is closed

module.close()

View source on GitHub

Close the WebSocket connection and stop reconnecting

module.me(cb?)

View source on GitHub

Get information about the current wallet Starting in 1.0.1, this data is passed by the "connected" event for easy access

Parameters:

module.send(data, cb?)

View source on GitHub

Send a Kromer transaction

Parameters:

module.addCheck(name, checkFn)

View source on GitHub

Add a custom check function that runs before processing a refund. This can be used to implement additional safeguards or restrictions on refunds, such as checking against an external database or applying custom business logic. The check function should return `true` if the refund is allowed, or `false` and an error message if it should be blocked.

Parameters:

module.removeCheck(name)

View source on GitHub

Remove a previously added refund check by name

Parameters: