lemojs-lib
General purpose library for the LEMO blockchain.
Fork from eosjs
Usage (read-only)
Lemo = // Lemo = require('./src') // lemo = Lemo.Localnet() // 127.0.0.1:8888lemo = Lemo // testnet at lemo.io // All API methods print help when called with no-arguments.lemo // Next, your going to need lemod running on localhost:8888 // If a callback is not provided, a Promise is returnedlemo // Parameters can be sequential or an objectlemo // Callbacks are similar {err ? console : console}lemolemo // Provide an empty object or a callback if an API call has no argumentslemo
Configuration
Lemo = // Lemo = require('./src') // Optional configuration..config = keyProvider: 'PrivateKeys...' // WIF string or array of keys.. httpEndpoint: 'http://127.0.0.1:8888' 'pass' // or 'fail' { } expireInSeconds: 60 broadcast: true debug: false sign: true lemo = Lemo
-
mockTransactions
(optional)pass
- do not broadcast, always pretend that the transaction workedfail
- do not broadcast, pretend the transaction failednull|undefined
- broadcast as usual
-
transactionHeaders
(optional) - manually calculate transaction header. This may be provided so lemojs-lib does not need to make header related API calls to eosd. This callback is called for every transaction.
Options
Options may be provided immediately after parameters.
Example: lemo.transfer(params, options)
options = broadcast: true sign: true scope: null authorization: null
-
scope
{array<string>|string}
- account name or names that may undergo a change in state.- If missing default scopes will be calculated.
- If provided additional scopes will not be added.
- Sorting is always performed.
-
authorization
{array<auth>|auth}
- identifies the signing account and permission typically in a multi-sig configuration. Authorization may be a string formatted asaccount@permission
or anobject<{account, permission}>
.- If missing default authorizations will be calculated.
- If provided additional authorizations will not be added.
- Sorting is always performed (by account name).
Usage (read/write)
If you use the Testnet, you'll need to replace the private key in keyProvider.
Lemo = // Lemo = require('./src') lemo = Lemo // Run with no arguments to print usage.lemo // Usage with options (options are always optional)options = broadcast: falselemo // Object or ordered args may be used.lemo // A broadcast boolean may be provided as a shortcut for {broadcast: false}lemo
Shorthand
Shorthand is available for some types such as Asset and Authority.
For example:
- deposit:
'1 EOS'
is shorthand for1.0000 EOS
- owner:
'EOS6MRy..'
is shorthand for{threshold: 1, keys: [key: 'EOS6MRy..', weight: 1]}
- recovery:
inita
orinita@active
is shorthand{{threshold: 1, accounts: [..account: inita, permission: active, weight: 1]}}
inita@other
would replace the permissionactive
withother
Lemo = // Lemo = require('./src') initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3'initaPublic = 'EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV'keyProvider = initaPrivate lemo = Lemo lemo
Contract
Deploy a smart contract.
The setcode
command accepts WASM text and converts this to binary before
signing and broadcasting. For this, the Binaryen library is used. Because
this is a large library it is not included in lemojs-lib
by default.
Add binaryen to your project:
npm i binaryen
Import and include the library when you configure Lemo:
const binaryen = lemo = Lemo
Complete example:
Lemo = // Lemo = require('./src')let ecc = Lemomodules initaPrivate = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' // New deterministic key for the currency account. Only use a simple// seedPrivate in production if you want to give away money.currencyPrivate = ecccurrencyPublic = ecc keyProvider = initaPrivate currencyPrivate // Requires a large library, separate from the lemojs-lib bundle// $ npm install binaryenbinaryen = lemo = Lemo lemo contractDir = `/lemoio/lemo/build/contracts/currency`wast = fsabi = fs // Publish contract to the blockchainlemo // lemo.contract(code<string>, [options], [callback])lemo
Atomic Operations
Blockchain level atomic operations. All will pass or fail.
Lemo = // Lemo = require('./src') keyProvider = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3' Lemomodulesecc testnet = Lemo // if either transfer fails, both will fail (1 transaction, 2 messages)testnet // transaction on a single contracttestnet // mix contracts in the same transactiontestnet // contract lookups then transactionstestnet // Note, the contract method does not take an array. Just use Await or yield// if multiple contracts are needed outside of a transaction.
Usage (manual)
A manual transaction provides for more flexibility.
Lemo = // Lemo = require('./src') lemo = Lemo lemo
Development
From time-to-time the lemojs-lib and lemod binary format will change between releases
so you may need to start lemod
with the --skip-transaction-signatures
parameter
to get your transactions to pass.
Note, package.json
has a "main" pointing to ./lib
. The ./lib
folder is for
es2015 code built in a separate step. If your changing and testing code,
import from ./src
instead.
Lemo =
Use Node v8+ to package-lock.json
.
Related Libraries
These libraries are exported from lemojs-lib
or may be used separately.
var api ecc json Fcbuffer format = Lemomodules
-
format ./format.md
- Blockchain name validation
- Asset string formatting
-
- Remote API to an EOS blockchain node (eosd)
- Use this library directly if you need read-only access to the blockchain (don't need to sign transactions).
-
- Private Key, Public Key, Signature, AES, Encryption / Decryption
- Validate public or private keys
- Encrypt or decrypt with EOS compatible checksums
- Calculate a shared secret
-
- Blockchain definitions (api method names, blockchain operations, etc)
- Maybe used by any language that can parse json
- Kept up-to-date
-
lemojs-lib-keygen [Github, NPM]
- private key storage and key management
-
- Binary serialization used by the blockchain
- Clients sign the binary form of the transaction
- Essential so the client knows what it is signing
Browser
git clone https://github.com/LemoFoundationLtd/lemojs-lib.gitcd lemojs-libnpm installnpm run build# builds: ./dist/lemo.js
Environment
Node 6+ and browser (browserify, webpack, etc)
React Native should work, create an issue if you find a bug.