SPK-JS Progress - Account Functions

in #spklast year

SPK-JS

Has recieved another batch of code. This time around every function an account can trigger through broadcasting to Hive is written. I can think of a few places this can improve, especially in error checking... But it's a great place to start.

Build instructions are as follows:

git clone https://github.com/disregardfiat/spk-js.git
cd spk-js
npm install (Assumes you already have node-js)
npm run build-browser

From there you can copy the distro to your html page and run wild.

API and Broadcast Setup Instructions

Craiyon - "A picture an AI would want their mom to hang on the fridge" A little creative freedom never hurt.

Account

Used for account management. The setAccount method is required for all other functionality.

Set Account

spkJs.account.setAccount("disregardfiat")

Initialize the suite with the account of the pages key holder

Channel Open

spkJs.account.channelOpen(broca, uploader, broker, benAmount = "", benAccount = "")

BROCA = 10000
Account to Upload File = disregardfiat
broker: IPFS Service Provider = dlux-io
Requested Benificary Amount = 10.00
Benificiary Account = dlux-io

DEX Buy

spkJs.account.dexBuy(amount, rate = 0, type = "HIVE", hours = 720)

amount in milliHive or milliHBD
rate for limit orders, 0 for market
type: HIVE or HBD
hours: 720 max, 1 min

Examples:

Market Order 1 Hive
spkJs.account.dexBuy(1000)

Market Order 1 HBD
spkJs.account.dexBuy(1000,0,"HBD")

Limit Order 1 Hive @ .0144

spkJs.account.dexBuy(1000, 0.0144)

DEX Cancel

spkJs.account.dexCancel(txid)

Cancel an open order. Refunds happen in 1 to 9 minutes for Hive, and instantly for LARYNX.

DEX Sell

spkJs.account.dexSell(amount, rate = 0, type = "HIVE", hours = 720)

Much like above. amount in milliHive or HBD

Examples:

Market Sell Order 1 Larynx for Hive
spkJs.account.dexSell(1000)

Market Sell Order 1 Larynx for HBD
spkJs.account.dexSell(1000,0,"HBD")

Limit Order Sell 1 Larynx @ .0144

spkJs.account.dexSell(1000, 0.0144)

Extend

spkJs.account.extend(cid, fileOwner, broca, power = 0)

cid => contract ID : markegiles:0:74019097
fileOwner => markegiles
broca => amount to send to contract
power => 0 || 1
1 will buy an extra slot for the decentralization.

Gov Down

spkJs.account.govDown(amount)

Amount in milliLarynx Gov to transform

Gov Up

spkJs.account.govUp(amount)

Amount in milliLarynx to transform

Power Down

spkJs.account.powerDown(amount)

Amount in milliLarynx Power to transform

Power Grant

spkJs.account.powerGrant()

Power Up

spkJs.account.powerUp(amount)

Amount in milliLarynx to transform

Register Authority

Registers a Hive Pubkey to the SPK Layer 2.
It is not recommended to include a pubKey here, the accounts first posting key auth will be used in it's absence.

spkJs.account.registerAuthority(pubKey = "")

Register Service

spkJs.account.registerService(type = "IPFS", id, api, amount = 2000)

amount in MiliLarynx Liquid
id => peerID of IPFS
api => https://ipfs.dlux.io
type => "IPFS"

You can also register service types, but this form will trigger Proof of Access storage.

Register Service Type

spkJs.account.registerServiceType(type, amount, name)

Used for registering API types. There is a cost associated.

type: IPFS
amount: 2000
name: InterplanetaryFileSystem

Remove

Removes your storage node from a file contract.

spkJs.account.remove(item~s)

Takes a contract ID, or an array of contract IDs.
Will generate a broadcast of items the account is storing to be removed.

Send LARYNX

Send Larynx tokens to another Hive account

spkJs.account.sendLarynx(amount, to, memo = "", test = false)

Amount is in integer units. 1.000 Larynx is 1000
Function checks for current Larynx amount, will error on insufficient funds.
Function checks for hive account recieving, will error on unregistered account.
Memo is not required
true test will insert a T in the custom json string and only the test network will accept the transaction

Send SPK

Send SPK tokens to another Hive account

spkJs.account.sendSpk(amount, to, memo = "", test = false)

Amount is in integer units. 1.000 SPK is 1000
Function checks for current SPK amount, will error on insufficient funds.
Function checks for hive account recieving, will error on unregistered account.
Memo is not required
true test will insert a T in the custom json string and only the test network will accept the transaction

Claim

Function to claim reward Larynx. Will fail if there is no claim availible. The optional gov BOOL will claim half to the collateral state instead of the power state, which is only availible to SPK Node operators (and will fail to false if not running a node with the account)

spkJs.account.claim(gov = false)

SPK Down

spkJs.account.spkDown(amount)

Amount in milliSPK Power to transform

SPK Up

spkJs.account.spkUp(amount)

Amount in milliSPK to transform

SPK Vote

spkJs.account.spkVote(votes = {})

Implementation lacking. The api.getProtocol includes the allowed votable keys, the votes object should be checked against this as well as allowed as determined by the current values (getStats()).

Example:

spkJs.account.spkVote({
spk_cycle_length: "201000.000000",
dex_fee: "0.006"
})

Validator Vote

Used for ranked choice validator voting. Each validator has a code used for voting, fill in up to 30 of these codes in an array and call this function.

spkJs.account.valVote(votes = [])

Validator Register

This will register your SPK Node as a validator node, which will perform of chain actions such as requesting and verifying files stored on the network. Validator nodes can be voted on to increase the size of their lottery drawings / payout potential. Can also use to increase the fee burned to validator.

spkJs.account.validatorBurn(amount)

Amount in milliLarynx : INT
Amount must be >= stats.IPFSRate (spam filter)
Account must have registered SPK Network Node

Sort:  

Congratulations @disregardfiat! You received a personal badge!

You powered-up at least 1000 HP on Hive Power Up Day and got the biggest Power-Bee!
See you at the next Power Up day to see if you will repeat this feat.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Check out our last posts:

Hive Power Up Month Challenge - May 2023 Winners List
Be ready for the June edition of the Hive Power Up Month!
Unveiling the Exclusive Web3 Berlin Conference Badge. HiveBuzz Adds a Touch of Excitement!

Congratulations @disregardfiat! You received a personal badge!

You powered-up at least 10 HIVE on Hive Power Up Day!
Wait until the end of Power Up Day to find out the size of your Power-Bee.
May the Hive Power be with you!

You can view your badges on your board and compare yourself to others in the Ranking

Check out our last posts:

Hive Power Up Month Challenge - June 2023 Winners List
Be ready for the July edition of the Hive Power Up Month!
Hive Power Up Day - July 1st 2023