lemo-core-sdk v0.12.1

LemoChain Core SDK
This is the LemoChain Core node SDK which implements the Generic JSON RPC.
You need to run a local LemoChain Core node with flag
--rpcor connect to a remote LemoChain Core node to use this library.
Installing
Using Yarn
yarn add lemo-core-sdkAs Browser module
- Include
lemo-core-sdk.min.jsin your html file. - Use the
LemoCoreobject directly from global namespace
Example
const LemoCore = require('lemo-core-sdk')
const lemo = new LemoCore({
host: 'http://127.0.0.1:8001'
})
lemo.chain.getBlockByNumber(0).then(function(block) {
console.log(block)
})LemoChain Core API
Almost every API returns a promise object, except
watchXXX,stopWatchand so on
All API available in the console of LemoChain core. But some APIs are not available over remote connection such as http, websocket
| API | description | asynchronous | available for remote |
|---|---|---|---|
| lemo.getBlock(heightOrHash, withBody) | Get block by height or block hash | ✓ | ✓ |
| lemo.getNewestBlock(withBody) | Get the newest block | ✓ | ✓ |
| lemo.getNewestUnstableBlock() | Get the newest unstable block | ✓ | |
| lemo.getNewestHeight() | Get the newest block height | ✓ | ✓ |
| lemo.getNewestUnstableHeight() | Get the newest unstable block height | ✓ | |
| lemo.getGenesis() | Get the first block | ✓ | ✓ |
| lemo.getChainID() | Get the chain ID | ✓ | ✓ |
| lemo.getCandidateTop30() | Get top 30 candidates information | ✓ | ✓ |
| lemo.getDeputyNodeList(onlyBlockSigner) | Get information of current deputy nodes | ✓ | ✓ |
| lemo.getTermReward(height) | Get miners' reward in current term | ✓ | ✓ |
| lemo.getAllRewardValue() | Get all reward information | ✓ | ✓ |
| lemo.getNodeVersion() | Get the version of LemoChain node | ✓ | ✓ |
| lemo.watchBlock(withBody, callback) | Listen for new block | ✓ | |
| lemo.stopWatchBlock(subscribeId) | Stop listening block | ✓ | |
| lemo.net.connect(nodeAddr) | Connect to a LemoChain node | ✓ | |
| lemo.net.disconnect(nodeAddr) | Disconnect to a LemoChain node | ✓ | |
| lemo.net.getConnections() | Get the information of connections | ✓ | |
| lemo.net.getConnectionsCount() | Get the count of connections | ✓ | ✓ |
| lemo.net.getInfo() | Get current node information | ✓ | ✓ |
| lemo.net.getNodeID() | Gets the nodeID of the current node | ✓ | ✓ |
| lemo.net.broadcastConfirm(hash) | broadcast confirms of a block | ✓ | |
| lemo.net.fetchConfirm(height) | Pulls the acknowledgement packet for the specified height block | ✓ | |
| lemo.mine.start() | Start mining | ✓ | |
| lemo.mine.stop() | Stop mining | ✓ | |
| lemo.mine.getMining() | True if current LemoChain node is mining | ✓ | ✓ |
| lemo.mine.getMiner() | Get the mining benefit account address of current LemoChain node | ✓ | ✓ |
| lemo.account.newKeyPair() | Create a private key and account address | ✓ | ✓ |
| lemo.account.getBalance(addr) | Get the balance of an account | ✓ | ✓ |
| lemo.account.getAccount(addr) | Get the information of an account | ✓ | ✓ |
| lemo.account.getCandidateInfo(addr) | Get the information of an candidate | ✓ | ✓ |
| lemo.account.getVoteFor(addr) | Get voting information from account | ✓ | ✓ |
| lemo.account.getEquity(addr, assetId) | Get the balance of asset from account | ✓ | ✓ |
| lemo.account.createTempAddress(from, userId) | create a temp address | ✓ | |
| lemo.account.isTempAddress(address) | True if the current address is a temporary account | ✓ | |
| lemo.account.isContractAddress(address) | True if the current address is a contract account | ✓ | |
| lemo.tx.send(txConfig, privateKey) | Send transaction | ✓ | ✓ |
| lemo.tx.waitConfirm(txHash) | wait for the transaction to be confirmed | ✓ | ✓ |
| lemo.tx.watchTx(filterTxConfig, callback) | listen and filter for transaction of block | ✓ | |
| lemo.tx.stopWatchTx(subscribeId) | Stop listening transaction | ✓ | |
| lemo.stopWatch() | Stop listening | ✓ | |
| lemo.isWatching() | True if is listening | ✓ |
| Class Properties | description |
|---|---|
| LemoCore.SDK_VERSION | The version of js SDK |
| LemoCore.TxType | Enum of transaction type |
| LemoCore.ChangeLogType | Enum of change log type |
| LemoCore.BigNumber | The BigNumber library |
Protocol
Send and receive data by json format, use JSON-RPC2.0 standard.
For convenient, all numbers will be convert to string. So the numbers will never overflow.
POST request
{
"jsonrpc": "2.0",
"method": "chain_getBlockByHeight",
"params": [1, false],
"id": 1
}jsonrpc- (string) Always2.0method- (string) API module name and method name connected by_params- (Array) API method parameters, object is availableid- (number) Increasing request id
Success response
{
"jsonrpc": "2.0",
"result": {...},
"id": 1
}jsonrpc- (string) Always2.0result- (*) The result could be any typeid- (number) The id in request
Error response
{
"jsonrpc": "2.0",
"error": {"code": -32601, "message": "Method not found"},
"id": 1
}jsonrpc- (string) Always2.0error- (object) The error detail. It contains a negtive numbercodeand a stringmessage.id- (number) The id in request
Data structure
block
{
"header": {},
"transactions": [],
"changeLogs": [],
"confirms": [],
"events": [],
"deputyNodes": []
}headerThe header of blocktransactionsAll Transactions in blockchangeLogsThe account data changeLogs by transactions in blockconfirmsThe signatures from deputies after they verified the blockeventsThe contract events from transactions in blockdeputyNodesNew deputy nodes information If the block issnapshot block, or else it is empty
header
The header of block
{
"hash": "0x11d9153b14adb92a14c16b66c3524d62b4742c0e7d375025525e2f131de37a8b",
"height": "0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"miner": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"signData": "0x",
"timestamp": "1535630400",
"gasLimit": "105000000",
"gasUsed": "0",
"eventBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"changeLogRoot": "0x93273cebb4f0728991811d5d7c57ae8f88a83524eedb0af48b3061ed2e8017b8",
"deputyRoot": "0x49b613bbdf76be3fe761fd60d1ade6d2835315047c53d6e8199737898b8d9b47",
"eventRoot": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"transactionRoot": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"versionRoot": "0x1e78c4779248d3d8d3cd9b77bf7b67b4c759ec87d45d52a3e79c928290773f4c",
"extraData": ""
}hashBlock hashheightBlock heightparentHashPrevious block hashminerAddress of the account who produce this blocksignDataMiner's signatue of the block hashtimestampThe time of block creation in secondsgasLimitMax gas limit for all transactions in blockgasUsedUsed gas of all transactions in blockeventBloomThe bloom filter for speed up contract events query. Calculated byeventsin blockchangeLogRootThe root hash of block'schangeLogsMerkle TriedeputyRootThe root hash of block'sdeputyNodesMerkle TrieeventRootThe root hash of block'seventsMerkle TrietransactionRootThe root hash of block'stransactionsMerkle TrieversionRootThe root hash of globalversionsMerkle Patricia Trie. This trie is storing all accounts' newest versionextraData(optional) The custom data from miner
transaction
Signed transaction
{
"type": "1",
"chainID": "1",
"version": "1",
"from": "Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D",
"to": "Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY",
"gasPayer": "",
"toName": "",
"amount": "100",
"data": "0x",
"expirationTime": 1541566996,
"gasLimit": 2000000,
"gasPrice": "3000000000",
"hash": "0x6d3062a9f5d4400b2002b436bc69485449891c83e23bf9e27229234da5b25dcf",
"message": "",
"sigs": ["0xd9a9f9f41ea020185a6480fe6938d776f0a675d89057c071fc890e09742a4dd96edb9d48c9978c2f12fbde0d0445f2ff5f08a448b91469511c663567d0b015f601"],
"gasPayerSigs": ["0x800be6a0cf31ab9e86d547fb8cf964339276233a2b260ad8a4b4c93b39a48d6b1761e125f601bc6953e30eaad3e698c12add332a5740f1618915c12432dc610601"]
}typeThe type of transactionchainIDThe LemoChain IDversionCurrent transaction version, Between 0 and 128fromSender address.toRecipient addressgasPayerAccount address of gas reimbursement agenttoName(optional) Recipient name. It will be checked withtofor safe. The max limit of length is 100.amountAmount inmo. It is aBigNumberobject. 1LEMO=1000000000000000000mo=1e18modata(optional) The extra data. It usually using for calling smart contract. It depends ontypethat how to using this fieldexpirationTimeThe expiration time of transaction in seconds. If a transaction's expiration time is more than half hour from now, it may not be packaged in block. It depends on the transactions picking logic from minergasLimitMax gas limit of transaction. The transaction will be fail if it cost more gas than gasLimit. And the gas will not be refundedgasPricePrice of every gas inmo. It is aBigNumberobject. The more gas price the more priorityhashTransaction hashmessage(optional) Extra text message from sender. The max limit of length is 1024.sigsTransaction signature array, each field length is 65 bytesgasPayerSigsAn array of paid gas transaction signature data, each field length is 65 bytes
| transaction type | number value | description |
|---|---|---|
| lemo.TxType.ORDINARY | 0 | Normal transaction or smart contract execution transaction |
| lemo.TxType.CREATE_CONTRACT | 1 | Create contract |
| lemo.TxType.VOTE | 2 | Set vote target |
| lemo.TxType.CANDIDATE | 3 | Register or modify candidate information |
| lemo.TxType.CREATE_ASSET | 4 | Create asset information |
| lemo.TxType.ISSUE_ASSET | 5 | Issue asset |
| lemo.TxType.REPLENISH_ASSET | 6 | Replenish asset transaction |
| lemo.TxType.MODIFY_ASSET | 7 | Modify asset transaction |
| lemo.TxType.TRANSFER_ASSET | 8 | Transfer assets |
| lemo.TxType.MODIFY_SIGNER | 9 | Modify account signers |
| lemo.TxType.BOX_TX | 10 | Package multiple transactions and run them transactional |
| chainID | description |
|---|---|
| 1 | LemoChain main net |
| 100 | LemoChain test net |
changeLog
The modification record of data on chain
{
"address": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"extra": "",
"newValue": "0x8c052b7d2dcc80cd2e40000000",
"type": "BalanceLog",
"version": 1
}addressThe address of account which data is changedversionThe version of account data. Every type data has its own version- Depends on different
type, thenewValueandextrahave different functions
| type | number value | description | newValue | extra |
|---|---|---|---|---|
| lemo.ChangeLogType.BalanceLog | 1 | The change of account balance | New balance | - |
| lemo.ChangeLogType.StorageLog | 2 | The change of storage in contract account | storage value | storage key |
| lemo.ChangeLogType.StorageRootLog | 3 | The change of the storage trie's root in contract account | storage root hash | - |
| lemo.ChangeLogType.AssetCodeLog | 4 | Creation of asset type information | whole information of asset type | asset code |
| lemo.ChangeLogType.AssetCodeStateLog | 5 | The change of one asset profile field | field value | asset code and field key |
| lemo.ChangeLogType.AssetCodeRootLog | 6 | The change of the asset code trie's root in account | asset code root hash | - |
| lemo.ChangeLogType.AssetCodeTotalSupplyLog | 7 | Issue, replenish or destory asset | asset supply amount | asset code |
| lemo.ChangeLogType.AssetIdLog | 8 | Issue asset token or modify its metadata | asset metadata in asset token | asset id |
| lemo.ChangeLogType.AssetIdRootLog | 9 | The change of the asset metadata trie's root in account | asset metadata root hash | - |
| lemo.ChangeLogType.EquityLog | 10 | The change of equity which owned by the account | asset equity information | asset id |
| lemo.ChangeLogType.EquityRootLog | 11 | The change of the equity trie's root in account | equity root hash | - |
| lemo.ChangeLogType.CandidateLog | 12 | Creation or modification of candidate profile | candidate profile map | - |
| lemo.ChangeLogType.CandidateStateLog | 13 | The change of one candidate profile field in account | field value | field key |
| lemo.ChangeLogType.CodeLog | 14 | Creation of contract account | Contract's code | - |
| lemo.ChangeLogType.AddEventLog | 15 | A contract event has been made | Contract event | - |
| lemo.ChangeLogType.SuicideLog | 16 | Destroying a contract account | - | - |
| lemo.ChangeLogType.VoteForLog | 17 | The change of vote target address in account | new vote target address | - |
| lemo.ChangeLogType.VotesLog | 18 | The change of received votes count in candidate account | new votes count | - |
| lemo.ChangeLogType.SignersLog | 19 | The change of singers address and weight of the account | signers profile map | - |
confirm
The signature of block hash from a deputy node after him verified the block
0x1234event
Smart contract event
{
"address": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
}deputyNode
Deputy node information
{
"minerAddress": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"nodeID": "0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0",
"host": "127.0.0.1",
"port": "7001",
"votes": "50000"
}minerAddressThe account address to receive mining benefitnodeIDThe LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with0xhostDeputy node IP address or domain. The max limit of length is 128.portThe port to connect other nodesvotesThe votes count
account
Account information
{
"address": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"assetCodeRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"assetIdRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"balance": "1599999999999999999999999900",
"records": {
"BalanceLog": {
"version": 3,
"height": 1
}
},
"codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"equityRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"root": "0x0000000000000000000000000000000000000000000000000000000000000000",
"txCount": 0,
"voteFor": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"candidate": {
"votes": "1599999000",
"profile": {
"host": "www.lemochain.com",
"isCandidate": "true",
"minerAddress": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"nodeID": "0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0",
"port": "7001"
}
},
"signers": [{"address": "Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY","weight": "60"}, {"address": "Lemo842BJZ4DKCC764C63Y6A943775JH6NQ3Z33Y", "weight": "50"}]
}addressAccount addressassetCodeRootThe hash of created assets MPT rootassetIdRootThe hash of issued assets MPT rootbalanceAccount balance. It is a modifiedBigNumberobject. It has a methodtoMoney()to output formatted balancerecordsModification record object of account. The key is type of ChangeLog, value is the newestChangeLog's version and height of the block which contains this newestChangeLogcodeHashHash of contract codeequityRootThe hash of asset equities MPT rootrootThe hash of contract storage MPT roottxCountTransactions count from or to this accountvoteForVote target address of this accountcandidateIf this account is a consensus candidate, then this property existvotesReceived votes count for a candidate accountprofileCandidate account profilehostIP or domain of the candidate node serverisCandidateThis account is or isn't a candidate. It is used to cancel candidateminerAddressThe address of miner account who receive miner benefitnodeIDThe LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with0xportPort of the candidate node server
signersThe signers for a multi-sign account. It is necessary to collect over 100 weight to sign a transactionaddressThe signer's account addressweightWeight for the signer
Constructor
lemo = new LemoCore({
chainID: 1,
host: 'http://127.0.0.1:8001'
})chainIDThe ID of LemoChain. Default value is1, it represents main nethostLemoChain node's HTTP listening address. The default value ishttp://127.0.0.1:8001NOTE: If the cross domain issue appear. Try to use flag
--rpccorsdomain http://[domain of the web page]:[port]to restart LemoChain node.
chain API
lemo.getBlock
lemo.getBlock(heightOrHash [, withBody])Get block by height or block hash
Parameters
number|string- Block height or block hash. If it is block height, only stable blocks will be retrived which confirmed by most deputy nodesboolean- (optional) Enable to get block body such as transactions. Default value isfalse
Returns
Promise - Call then method to get block object
Example
lemo.getBlock(0).then(function(block) {
console.log(block.header.hash) // "0x11d9153b14adb92a14c16b66c3524d62b4742c0e7d375025525e2f131de37a8b"
})lemo.getNewestBlock
lemo.getNewestBlock([withBody])Get the newest block
Parameters
boolean- (optional) Enable to get block body such as transactions. Default value isfalse
Returns
Promise - Call then method to get block object
Example
lemo.getNewestBlock(true).then(function(block) {
console.log(block.header.miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})lemo.getNewestUnstableBlock
lemo.getNewestUnstableBlock()Get the newest unstable block which may not has enough confirms by deputy nodes
Parameters
None
Returns
Promise - Call then method to get block object with body
Example
lemo.getNewestUnstableBlock().then(function(block) {
console.log(block.header.miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})lemo.getNewestHeight
lemo.getNewestHeight()Get the newest block height
Parameters
None
Returns
Promise - Call then method to get height string
Example
lemo.getNewestHeight().then(function(height) {
console.log(height) // "100"
})lemo.getNewestUnstableHeight
lemo.getNewestUnstableHeight()Get the newest unstable block height
Parameters
None
Returns
Promise - Call then method to get height string
Example
lemo.getNewestUnstableHeight().then(function(height) {
console.log(height) // "100"
})lemo.getGenesis
lemo.getGenesis()Get the first block
Parameters
None
Returns
Promise - Call then method to get block object
Example
lemo.getGenesis().then(function(block) {
console.log(block.header.parentHash) // "0x0000000000000000000000000000000000000000000000000000000000000000"
})lemo.getChainID
lemo.getChainID()Get the chain ID from current connected LemoChain node
Parameters
None
Returns
Promise - Call then method to get chainID string
Example
lemo.getChainID().then(function(chainID) {
console.log(chainID) // "1"
})lemo.getCandidateTop30
lemo.getCandidateTop30()Get top 30 candidates information
Parameters
None
Returns
Promise - Call then method to get a candidate information list. The item in list is very similar with candidate in account. There is an account address field in every candidate item
Example
lemo.getCandidateTop30().then(function(candidateList) {
console.log(candidateList.length) // 1
console.log(candidateList[0].address) // Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG
console.log(JSON.stringify(candidateList)) // [{"address":"Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG","profile":{"host":"127.0.0.1","isCandidate":true,"minerAddress":"Lemobw","nodeID":"0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0","port":7001},"votes":"1599999000"}]
})lemo.getDeputyNodeList
lemo.getDeputyNodeList(onlyBlockSigner)Get information of current deputy nodes
Parameters
boolean- (Optional) If true it returns deputy node information of who can currently sign blocks, false returns who has become deputy node from candidate in current stable state.
Returns
Promise - Call then method to get the information list of current deputy nodes
minerAddress - (string)The address of miner account who receive miner benefit
incomeAddress - (string)Nodal incomeAddress
nodeID - (string)The LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with 0x
rank - (string)The rank of the outgoing node
votes - (string)Node votes
host - (string)Domain or IP of the candidate node server
port - (string)Port of the candidate node server
depositAmount - (string)deposit amount
introduction - (string)Introduction of node
p2pUri - (string)Connection uri of a LemoChain node. The address can be used to connect LemoChain node.
Example
lemo.getDeputyNodeList(true).then(function(nodeList) {
console.log(nodeList.length) // 1
console.log(JSON.stringify(nodeList[0]))
// "{"minerAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","incomeAddress":"Lemo83DZ5J99JSK5ZH89TCW7T6ZZCWJ8H7FDGA7W","nodeID":"0x0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0","rank":0,"votes":"50000","host":"127.0.0.1","port":8080,"depositAmount":"5000000000000000000000000","introduction":"ddf","p2pUri":"0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0@127.0.0.1:8080"}"
lemo.net.connect(nodeList[0].p2pUri)
})lemo.getTermReward
lemo.getTermReward(height)Get miners' reward in current term
Parameters
number- the height of block which used to find the term reward block in same term
Returns
object - Term reward information,includes:
term - (number)Term index, starting from 0
value - (string)The total amount of reward for all miners, The unit is mo
rewardHeight - (number)The height of reward block
Example
lemo.getTermReward(1001).then(function(result){
console.log(JSON.stringify(result)) // {"term":0,"value":"1000000000","rewardHeight":10001}
})lemo.getAllRewardValue
lemo.getAllRewardValue()Get all miners' award information for the chain
Parameters
None
Returns
object - Miners' award information,includes:
term - (number)Terms index, starting at 0
value - (string)The total amount of awards given
times - (number)Updated times,times must be 1 or 2
Example
lemo.getAllRewardValue().then(function(result){
console.log(result) // { 0: { term: '1', value: '1000000001', times: '1' } }
})lemo.getNodeVersion
lemo.getNodeVersion()Get the version of LemoChain node
Parameters
None
Returns
Promise - Call then method to get version string
Example
lemo.getNodeVersion().then(function(version) {
console.log(version) // "1.0.0"
})lemo.watchBlock
lemo.watchBlock(withBody, callback)Listen for new block. The callback function will be called at the beginning and every times a new stable block produced.
Parameters
boolean- Enable to get block body such as transactions. Default value isfalseFunction- Used to receive block object
Returns
number - subscribeId, it is used to stop watching
Example
lemo.watchBlock(true, function(block) {
const d = new Date(1000 * parseInt(block.header.timestamp, 10))
console.log(d.toUTCString()) // "Thu, 30 Aug 2018 12:00:00 GMT"
})lemo.stopWatchBlock
lemo.stopWatchBlock(subscribeId)Stop watching and filtering transactions of block
Parameters
number- The subscribeId from watchBlock
Returns
None
Example
const subscribeId = lemo.watchBlock(false, function(newBlock) {
console.log(newBlock)
})
lemo.stopWatchBlock(subscribeId)net API
lemo.net.connect
lemo.net.connect(nodeAddr)Connect to a LemoChain node
Parameters
string- Node ID and IP address
Returns
Promise - No data input in then function
Example
lemo.net.connect('5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0@127.0.0.1:60002')lemo.net.disconnect
lemo.net.disconnect(nodeAddr)Disconnect to a LemoChain node
Parameters
string- ip address
Returns
Promise - Call then method to get boolean
Example
lemo.net.disconnect('127.0.0.1:60002').then(function(success) {
console.log(sucess ? 'success' : 'fail')
})lemo.net.getConnections
lemo.net.getConnections()Get the information of connections
Parameters
None
Returns
Promise - Call then method to get connection information list
Example
lemo.net.getConnections().then(function(connections) {
console.log(connections)
// [{
// localAddress: "127.0.0.1:50825",
// nodeID: "0xddb5fc36c415799e4c0cf7046ddde04aad6de8395d777db4f46ebdf258e55ee1d698fdd6f81a950f00b78bb0ea562e4f7de38cb0adf475c5026bb885ce74afb0",
// remoteAddress: "127.0.0.1:60002"
// }]
})lemo.net.getConnectionsCount
lemo.net.getConnectionsCount()Get the count of connections
Parameters
None
Returns
Promise - Call then method to get connection count
Example
lemo.net.getConnectionsCount().then(function(count) {
console.log(count) // "1"
})lemo.net.getInfo
lemo.net.getInfo()Get current node information
Parameters
None
Returns
Promise - Call then method to get node information
Example
lemo.net.getInfo().then(function(info) {
console.log(info.nodeName) // "Lemo"
console.log(info.nodeVersion) // "1.0.0"
console.log(info.os) // "windows-amd64"
console.log(info.port) // "60001"
console.log(info.runtime) // "go1.10.1"
})lemo.net.getNodeID
lemo.net.getNodeID()Get the nodeID of the current node
Parameters
None
Returns
Promise - Call then method to get the nodeID of the current node
Example
lemo.net.getNodeID().then(function(info) {
console.log(info) // "0x0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0"
})lemo.net.broadcastConfirm
lemo.net.broadcastConfirm(hash)broadcast confirms of a block
Parameters
string- block hash
Returns
None
Example
lemo.net.broadcastConfirm('0x6d3062a9f5d4400b2002b436bc69485449891c83e23bf9e27229234da5b25dcf')lemo.net.fetchConfirm
lemo.net.fetchConfirm(height)Pulls the confirms (signatures from miners) of the specified height block
Parameters
number- Block Height
Returns
None
Example
lemo.net.fetchConfirm(1001)mine API
lemo.mine.start
lemo.mine.start()Start mining
Parameters
None
Returns
Promise - No data input in then function
Example
lemo.mine.start()lemo.mine.stop
lemo.mine.stop()Stop mining
Parameters
None
Returns
Promise - No data input in then function
Example
lemo.mine.stop()lemo.mine.getMining
lemo.mine.getMining()True if current LemoChain node is mining
Parameters
None
Returns
Promise - Call then method to get boolean
Example
lemo.mine.getMining().then(function(isMining) {
console.log(isMining ? 'mining' : 'not mining')
})lemo.mine.getMiner
lemo.mine.getMiner()Get the account address to receive mining benefit
Parameters
None
Returns
Promise - Call then method to get account address
Example
lemo.mine.getMiner().then(function(miner) {
console.log(miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})account API
lemo.account.newKeyPair
lemo.account.newKeyPair()Create a private key and account address
Parameters
None
Returns
Promise - Call then method to get account key object
Example
const result = lemo.account.newKeyPair()
console.log(result.privateKey) // "0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52"
console.log(result.address) // "Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34"lemo.account.getBalance
lemo.account.getBalance(address)Get the balance of an account
Parameters
string- account address
Returns
Promise - Call then method to get balance BigNumber object
Example
lemo.account.getBalance('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34').then(function(balance) {
console.log(balance.toString(10)) // "1600000000000000000000000000"
})lemo.account.getAccount
lemo.account.getAccount(address)Get the information of an account
Parameters
string- account address
Returns
Promise - Call then method to get account information
Example
lemo.account.getAccount('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34').then(function(account) {
console.log(account.balance.toMoney()) // "1600000000 LEMO"
})lemo.account.getCandidateInfo
lemo.account.getCandidateInfo(address)Get the information of an candidate
Parameters
string- candidate account address
Returns
Promise - Call then method to get candidate information. It is same with candidate in account
Example
lemo.account.getCandidateInfo('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34')
.then(function(candidate) {
console.log(candidate.votes); // "1599999000"
})lemo.account.getVoteFor
lemo.account.getVoteFor(address)Get voting information from account
Parameters
string- lemo address
Returns
promise - return a vote target address
Example
lemo.account.getVoteFor('Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG')
.then(function(info) {
console.log(info); // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})lemo.account.getEquity
lemo.account.getEquity(address, assetId)Get the balance of asset from account
Parameters
string- The account addressstring- asset id
Returns
Promise - Call then method to get the balance of asset from account, includes:
assetCode - (string) asset code
assetId - (string) asset id
equity - (string) amount of asset
Example
lemo.account.getEquity('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', '0x34b04e018488f37f449193af2f24feb3b034c994cde95d30e3181403ac76528a')
.then(function(info) {
console.log(info.assetCode); // "0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884"
})lemo.account.createTempAddress
lemo.account.createTempAddress(from, userId)create a temp account
Parameters
string- account addressstring- customized user id, which's length should be 10 bytes in hexadecimal at most
Returns
string - Temporary account address
Example
const userId = '1110000000000000000'
const result = lemo.account.createTempAddress('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', userId)
console.log(result) // Lemo85SY56SGRTQQ63A2Y43KYA8C7QAZB37P3KY5lemo.account.isTempAddress
lemo.account.isTempAddress(address)Test whether the specific address is a temporary account or not
Parameters
string- Account address
Returns
boolean - True if the current address is a temporary account
Example
const result = lemo.account.isTempAddress('Lemo85SY56SGRTQQ63A2Y43KYA8C7QAZB37P3KY5')
console.log(result) // truelemo.account.isContractAddress
lemo.account.isContractAddress(address)Test whether the specific address is a contract account or not
Parameters
string- Account address
Returns
boolean - True if the current address is a contract account
Example
const result = lemo.account.isContractAddress('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D')
console.log(result) // falsetx API
lemo.tx.send
lemo.tx.send(txConfig, privateKey)Send a transaction
Parameters
LemoTx|object|string- Signed or unsigned transaction information. Or a LemoTx object or json string.string- (optional) Account private key, it will be used to sign if exist
Returns
Promise - Call then method to get transaction hash
Example
const txConfig = {from: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100}
lemo.tx.send(txConfig, '0xc21b6b2fbf230f665b936194d14da67187732bf9d28768aef1a3cbb26608f8aa').then(function(txHash) {
console.log(txHash) // 0x03fea27a8d140574dc648e1cb1a198f5ade450a347095cff7f3d961a11dac505
})const tx = new LemoTx({chainID: 100, from: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100})
tx.signWith('0xc21b6b2fbf230f665b936194d14da67187732bf9d28768aef1a3cbb26608f8aa')
lemo.tx.send(tx).then(function(txHash) {
console.log(txHash) // 0x03fea27a8d140574dc648e1cb1a198f5ade450a347095cff7f3d961a11dac505
})lemo.tx.waitConfirm
lemo.tx.waitConfirm(txHash)wait for the transaction to be confirmed
Parameters
string- transaction hash
Returns
Promise - Call then method to get transaction hash
Example
lemo.tx.waitConfirm(0xe71cd6d98b1e48ddccf36ed655700478971a8514abf7c4d2173512201222c6c0).then(function(result) {
console.log(JSON.stringify(result))
// {"blockHash":"0x425f4ca99da879aa97bd6feaef0d491096ff3437934a139f423fecf06f9fd5ab","height":"100","time":"1541649535","tx":{"chainID":200,"version":"1","type":"0","to":"Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH","toName":"aa","gasPrice":"2","gasLimit":"100","amount":"1","data":"0x0c","expirationTime":"1544584596","message":"aaa","from":"Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D","sigs":["0x8c0499083cb3d27bead4f21994aeebf8e75fa11df6bfe01c71cad583fc9a3c70778a437607d072540719a866adb630001fabbfb6b032d1a8dfbffac7daed8f0201"]}}
})lemo.tx.watchTx
lemo.tx.watchTx(filterTxConfig, callback)Listen for transactions of block. Returns an array with transactions from block body, and the value of the subscribeId
Parameters
object- This is the condition used to filter the transactions, can enter multiple attributesfunction- Used to receive transaction list
Returns
number - subscribeId, it is used to stop watching
Example
lemo.tx.watchTx({to:'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY'}, function(transaction) {
console.log(transaction[0].version)
}); //"1"
lemo.tx.watchTx({to:'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', from:'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}, function(transactions) {
console.log(transactions[0].version)
}); //"1"lemo.tx.stopWatchTx
lemo.tx.stopWatchTx(subscribeId)Stop watching and filtering transactions of block
Parameters
number- The subscribeId from watchTx
Returns
None
Example
const subscribeId = lemo.tx.watchTx({to:'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY'}, function(transactions) {
console.log(transactions[0].version)
});
lemo.tx.stopWatchTx(subscribeId)lemo.stopWatch
lemo.stopWatch()Stop all listening
Parameters
None
Returns
None
Example
lemo.stopWatch()lemo.isWatching
lemo.isWatching()True if is listening
Parameters
None
Returns
boolean - True if is listening
Example
console.log(lemo.isWatching() ? 'watching' : 'not watching')Class Properties
LemoCore.SDK_VERSION
LemoCore.SDK_VERSIONstring - The version of SDK
Example
console.log(LemoCore.SDK_VERSION) // "1.0.0"LemoCore.TxType
LemoCore.TxTypeEnum of transaction type, the value is number type
Example
console.log(LemoCore.TxType.VOTE) // 1LemoCore.ChangeLogType
LemoCore.ChangeLogTypeEnum of change log type, the value is number type
Example
console.log(LemoCore.ChangeLogType.BalanceLog) // 1Developing
Requirements
- Node.js
- yarn
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install yarnBuilding
yarn buildTesting
yarn testLicensing
LGPL-3.0
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago