2.0.15 • Published 3 years ago

koi_tools v2.0.15

Weekly downloads
53
License
ISC
Repository
github
Last release
3 years ago

Koi JavaScript SDK

The Koi.js library enables node.js and typescript applications to easily interact with the open Koi network.

Steps to Interact with the SDK in your Project

  1. Add the Koi-tools module to your node script and then initialize the koi class.

    const tools = require('koi-tools')
    var ktools = new tools()

    Note: This library changes often, so if npm i koi-tools does not work, you may also want to try installing the master branch of this repo directly with npm i git+https://github.com:open-koi/koi_tools.git to get the latest version.

  2. Optional - Add the Arweave module to your project if your app plans to directly transact with the permaweb outside of using the Koi-tools library

    const Arweave = require('arweave/node')
    const arweave = Arweave.init({
      host: 'arweave.net',
      protocol: 'https',
      port: 443
    });
  3. Create an RSA Wallet Key

    Note that the wallet address should not be held inside of your project when you check the project into GitHub

    var walletKeyLocation = "path/to/wallet.json";

    If you don't have a wallet, you can get one from the faucet at koi.rocks or the Arweave faucet at faucet.arweave.org.

  4. Define a function to bootstrap your app and utilize the koi-tools library loadWallet method to be returned the address of your wallet from the permaweb.

    async function start() {
    
      console.log("running async block", ktools)
    
      await ktools.loadWallet(walletKeyLocation)
    
      try {
        // define async functions here that interact with the koi library upon app startup such as verifying signed payloads
    
      } catch (err) {
        throw Error(err)
      }
    
    }
    
    start()

    If you are just testing with a local bundler, you can also use await ktools.generateWallet() to create a custom key file just for that runtime. (TODO: Expand support for 12 word seed phrase).

  5. Check out the test.js file held in this library with examples of how to interact with koi-tools.

Content Rewards

The Koi consensus process releases 1,000 KOI tokens per day to reward the best content that has ever been registered, proportional to the attention it receives in that time period.

Register arweave content like so:

var koiTools = require('koiTools');
var koi = new koiTools('/path/to/wallet.json')
var burnAmount = 5; // the amount of koi to burn on registration (burn more to earn more!)
var result = await koi.registerContent(< arweaveTxId >, burnAmount ? optional)
console.log('registered:', result)

Once this has been completed, your wallet will receive a portion of the daily KOI tokens every time your content is viewed.

If you do not have a KOI balance, you cannot participate. Your KOI will be burned to register the content.

Coming Soon: KOI Tasks

In order to ensure everyone has open access to the network, we're working on making it possible for nodes to run 'tasks' for each other to earn tokens.

Earning KOI

The default task is will be called StoreCat, which gathers web data and stores it on the permaweb archive. To run StoreCat, you can use a similar implementation to the one above.

var koiTools = require('koiTools');
var koi = new koiTools('/path/to/wallet.json')
var result = await koi.runTaskByRegisteredName('getstorecat')
console.log('task:', result)

Note: Some tasks take a while to execute, so the best way to run them is with the desktop node client.

Requesting Tasks

It will soon be possible to tap into the Koi network to request work. Once you have KOI tokens, you can set a bounty for a new task.

var koiTools = require('koiTools');
var koi = new koiTools('/path/to/wallet.json')
var koiTask = {
   id : "getstorecat", // unique global ID *see runTaskByRegisteredName above
   bounty : "5",       // bounty per result in KOI
   description : "
      Help StoreCat gather web data by running this simple web scraping task. The StoreCat does not have access to your computer, but will use your internet connection to browse the web.
   ", // long form description text
   expiry : new Date () + 5,       // expiry date after which unspent bounty tokens will be returned
   taskFile : " arweave TX ID of task file" // the execution environment currently supports most NPM bundles
}
var result = await koi.registerTask(koiTask)
console.log('registered:', result)

Webpack build procedure

yarn install
yarn build

Test with yarn test

Useful vscode settings

settings.json

    "eslint.validate": [
        "typescript",
        "typescriptreact",
    ],
    "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
    }
2.0.16

3 years ago

2.1.16-beta.5

3 years ago

2.1.16-beta.6

3 years ago

2.1.16-beta.3

3 years ago

2.1.16-beta.4

3 years ago

2.1.16-beta.9

3 years ago

2.1.16-beta.8

3 years ago

2.1.15-beta.7

3 years ago

2.1.16-beta.10

3 years ago

2.1.16-beta.11

3 years ago

2.0.16-beta.2

3 years ago

2.1.16-beta.12

3 years ago

2.0.15

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

2.0.5

3 years ago

2.0.11

3 years ago

2.0.7

3 years ago

2.0.12

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.3

3 years ago

2.0.4

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago