1.0.15 • Published 4 years ago

@eot/eot v1.0.15

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Economy Of Truth Client Module

To install

npm install @eot/eot or yarn add @eot/ept

Create a new instance:

const Eot = require('@eot/eot');

const options = {
    adminPort  : 9001 //the admin port number, 
    chargePort : 9002 //the charges port number,
    env        : 'development', //the environment you're in 
    url        : '3.82.0.126',  // the remote URL or IP of the servers
    pubId      : '2' // your publisher ID
};

const eot = new Eot(options); // the new instance

For performance the module uses callbacks rather than promises.

Create a user

The userRef is metadata you can add to the user that relates to your data. Perhaps it's the id of the user in your database.

function createUser() {
    eot.createUser(userRef, createUserCallBack);
}

function createUserCallBack(err, res) {
    // the res body contains the following 

    res.eotId // the id of the user in the EOT db
    res.pubId // your publisher id
    res.userRef // the metadata you added
}

Purchase Token For a User

// purchase 100 tokens for a user with an eotId of 12
eot.purchaseTokens(12, 100, purchaseCallback);

function purchaseCallback(err, res) {
   // res will be a boolean
   if(res){
     console.log('success!')
   }
}

Get Some Users Tokens

Tokens are not removed from a users account merely listed.

// get 3 tokens for a user with an eotId of 12
eot.getTokens(12, 3, getTokensCallback);

function getTokensCallback(err, res) {
  // res is an array of tokens
  console.log(res[0])
}

Charge a User

This will remove the token from the user and move it to your account, providng they have not already spent it.

// charge a user with an eotId of 247 using token 123abc
eot.charge(247, '123abc', chargeCallback);

function chargeCallback(err, res) {
  // res will be OK or ERROR.
  if(res === 'OK'){
    console.log('success')
  }

  if(res === 'ERROR'){
    console.log('User does not own this token')
  }
}
1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago