This is the LemoChain Core node SDK which implements the Generic JSON RPC.
You need to run a local LemoChain Core node with flag
--rpc
or connect to a remote LemoChain Core node to use this library.
yarn add lemo-core-sdk
- Include
lemo-core-sdk.min.js
in your html file. - Use the
LemoCore
object directly from global namespace
const LemoCore = require('lemo-core-sdk')
const lemo = new LemoCore({
host: 'http://127.0.0.1:8001'
})
lemo.getBlock(0).then(function(block) {
console.log(block)
})
Almost every API returns a promise object, except
watchXXX
,stopWatch
and 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 |
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.
{
"jsonrpc": "2.0",
"method": "chain_getBlockByHeight",
"params": [1, false],
"id": 1
}
jsonrpc
- (string) Always2.0
method
- (string) API module name and method name connected by_
params
- (Array) API method parameters, object is availableid
- (number) Increasing request id
{
"jsonrpc": "2.0",
"result": {...},
"id": 1
}
jsonrpc
- (string) Always2.0
result
- (*) The result could be any typeid
- (number) The id in request
{
"jsonrpc": "2.0",
"error": {"code": -32601, "message": "Method not found"},
"id": 1
}
jsonrpc
- (string) Always2.0
error
- (object) The error detail. It contains a negtive numbercode
and a stringmessage
.id
- (number) The id in request
{
"header": {},
"transactions": [],
"changeLogs": [],
"confirms": [],
"events": [],
"deputyNodes": []
}
header
The header of blocktransactions
All Transactions in blockchangeLogs
The account data changeLogs by transactions in blockconfirms
The signatures from deputies after they verified the blockevents
The contract events from transactions in blockdeputyNodes
New deputy nodes information If the block issnapshot block
, or else it is empty
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": ""
}
hash
Block hashheight
Block heightparentHash
Previous block hashminer
Address of the account who produce this blocksignData
Miner's signatue of the block hashtimestamp
The time of block creation in secondsgasLimit
Max gas limit for all transactions in blockgasUsed
Used gas of all transactions in blockeventBloom
The bloom filter for speed up contract events query. Calculated byevents
in blockchangeLogRoot
The root hash of block'schangeLogs
Merkle TriedeputyRoot
The root hash of block'sdeputyNodes
Merkle TrieeventRoot
The root hash of block'sevents
Merkle TrietransactionRoot
The root hash of block'stransactions
Merkle TrieversionRoot
The root hash of globalversions
Merkle Patricia Trie. This trie is storing all accounts' newest versionextraData
(optional) The custom data from miner
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"]
}
type
The type of transactionchainID
The LemoChain IDversion
Current transaction version, Between 0 and 128from
Sender address.to
Recipient addressgasPayer
Account address of gas reimbursement agenttoName
(optional) Recipient name. It will be checked withto
for safe. The max limit of length is 100.amount
Amount inmo
. It is aBigNumber
object. 1LEMO
=1000000000000000000mo
=1e18mo
data
(optional) The extra data. It usually using for calling smart contract. It depends ontype
that how to using this fieldexpirationTime
The 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 minergasLimit
Max gas limit of transaction. The transaction will be fail if it cost more gas than gasLimit. And the gas will not be refundedgasPrice
Price of every gas inmo
. It is aBigNumber
object. The more gas price the more priorityhash
Transaction hashmessage
(optional) Extra text message from sender. The max limit of length is 1024.sigs
Transaction signature array, each field length is 65 bytesgasPayerSigs
An 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 |
The modification record of data on chain
{
"address": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"extra": "",
"newValue": "0x8c052b7d2dcc80cd2e40000000",
"type": "BalanceLog",
"version": 1
}
address
The address of account which data is changedversion
The version of account data. Every type data has its own version- Depends on different
type
, thenewValue
andextra
have 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 | - |
The signature of block hash from a deputy node after him verified the block
0x1234
Smart contract event
{
"address": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
}
Deputy node information
{
"minerAddress": "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG",
"nodeID": "0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0",
"host": "127.0.0.1",
"port": "7001",
"votes": "50000"
}
minerAddress
The account address to receive mining benefitnodeID
The LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with0x
host
Deputy node IP address or domain. The max limit of length is 128.port
The port to connect other nodesvotes
The votes count
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"}]
}
address
Account addressassetCodeRoot
The hash of created assets MPT rootassetIdRoot
The hash of issued assets MPT rootbalance
Account balance. It is a modifiedBigNumber
object. It has a methodtoMoney()
to output formatted balancerecords
Modification record object of account. The key is type of ChangeLog, value is the newestChangeLog
's version and height of the block which contains this newestChangeLog
codeHash
Hash of contract codeequityRoot
The hash of asset equities MPT rootroot
The hash of contract storage MPT roottxCount
Transactions count from or to this accountvoteFor
Vote target address of this accountcandidate
If this account is a consensus candidate, then this property existvotes
Received votes count for a candidate accountprofile
Candidate account profilehost
IP or domain of the candidate node serverisCandidate
This account is or isn't a candidate. It is used to cancel candidateminerAddress
The address of miner account who receive miner benefitnodeID
The LemoChain node ID, it is from the public key whose private key is using for sign blocks. The length should be 130 characters with0x
port
Port of the candidate node server
signers
The signers for a multi-sign account. It is necessary to collect over 100 weight to sign a transactionaddress
The signer's account addressweight
Weight for the signer
lemo = new LemoCore({
chainID: 1,
host: 'http://127.0.0.1:8001'
})
chainID
The ID of LemoChain. Default value is1
, it represents main nethost
LemoChain node's HTTP listening address. The default value ishttp://127.0.0.1:8001
NOTE: If the cross domain issue appear. Try to use flag
--rpccorsdomain http://[domain of the web page]:[port]
to restart LemoChain node.
lemo.getBlock(heightOrHash [, withBody])
Get block by height or block hash
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
Promise
- Call then
method to get block object
lemo.getBlock(0).then(function(block) {
console.log(block.header.hash) // "0x11d9153b14adb92a14c16b66c3524d62b4742c0e7d375025525e2f131de37a8b"
})
lemo.getNewestBlock([withBody])
Get the newest block
boolean
- (optional) Enable to get block body such as transactions. Default value isfalse
Promise
- Call then
method to get block object
lemo.getNewestBlock(true).then(function(block) {
console.log(block.header.miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})
lemo.getNewestUnstableBlock()
Get the newest unstable block which may not has enough confirms by deputy nodes
None
Promise
- Call then
method to get block object with body
lemo.getNewestUnstableBlock().then(function(block) {
console.log(block.header.miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})
lemo.getNewestHeight()
Get the newest block height
None
Promise
- Call then
method to get height string
lemo.getNewestHeight().then(function(height) {
console.log(height) // "100"
})
lemo.getNewestUnstableHeight()
Get the newest unstable block height
None
Promise
- Call then
method to get height string
lemo.getNewestUnstableHeight().then(function(height) {
console.log(height) // "100"
})
lemo.getGenesis()
Get the first block
None
Promise
- Call then
method to get block object
lemo.getGenesis().then(function(block) {
console.log(block.header.parentHash) // "0x0000000000000000000000000000000000000000000000000000000000000000"
})
lemo.getChainID()
Get the chain ID from current connected LemoChain node
None
Promise
- Call then
method to get chainID string
lemo.getChainID().then(function(chainID) {
console.log(chainID) // "1"
})
lemo.getCandidateTop30()
Get top 30 candidates information
None
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
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(onlyBlockSigner)
Get information of current deputy nodes
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.
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.
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(height)
Get miners' reward in current term
number
- the height of block which used to find the term reward block in same term
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
lemo.getTermReward(1001).then(function(result){
console.log(JSON.stringify(result)) // {"term":0,"value":"1000000000","rewardHeight":10001}
})
lemo.getAllRewardValue()
Get all miners' award information for the chain
None
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
lemo.getAllRewardValue().then(function(result){
console.log(result) // { 0: { term: '1', value: '1000000001', times: '1' } }
})
lemo.getNodeVersion()
Get the version of LemoChain node
None
Promise
- Call then
method to get version string
lemo.getNodeVersion().then(function(version) {
console.log(version) // "1.0.0"
})
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.
boolean
- Enable to get block body such as transactions. Default value isfalse
Function
- Used to receive block object
number
- subscribeId, it is used to stop watching
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(subscribeId)
Stop watching and filtering transactions of block
number
- The subscribeId from watchBlock
None
const subscribeId = lemo.watchBlock(false, function(newBlock) {
console.log(newBlock)
})
lemo.stopWatchBlock(subscribeId)
lemo.net.connect(nodeAddr)
Connect to a LemoChain node
string
- Node ID and IP address
Promise
- No data input in then
function
lemo.net.connect('5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0@127.0.0.1:60002')
lemo.net.disconnect(nodeAddr)
Disconnect to a LemoChain node
string
- ip address
Promise
- Call then
method to get boolean
lemo.net.disconnect('127.0.0.1:60002').then(function(success) {
console.log(sucess ? 'success' : 'fail')
})
lemo.net.getConnections()
Get the information of connections
None
Promise
- Call then
method to get connection information list
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()
Get the count of connections
None
Promise
- Call then
method to get connection count
lemo.net.getConnectionsCount().then(function(count) {
console.log(count) // "1"
})
lemo.net.getInfo()
Get current node information
None
Promise
- Call then
method to get node information
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()
Get the nodeID of the current node
None
Promise
- Call then
method to get the nodeID of the current node
lemo.net.getNodeID().then(function(info) {
console.log(info) // "0x0e7dcd418dbe7717eb0e83162f8810a3c7725e0d386b324dc5f3ef5a27a2a83e393a193f6ab53d3a51b490adeee362357676f50eed3d188824ef1fb3af02b2d0"
})
lemo.net.broadcastConfirm(hash)
broadcast confirms of a block
string
- block hash
None
lemo.net.broadcastConfirm('0x6d3062a9f5d4400b2002b436bc69485449891c83e23bf9e27229234da5b25dcf')
lemo.net.fetchConfirm(height)
Pulls the confirms (signatures from miners) of the specified height block
number
- Block Height
None
lemo.net.fetchConfirm(1001)
lemo.mine.start()
Start mining
None
Promise
- No data input in then
function
lemo.mine.start()
lemo.mine.stop()
Stop mining
None
Promise
- No data input in then
function
lemo.mine.stop()
lemo.mine.getMining()
True if current LemoChain node is mining
None
Promise
- Call then
method to get boolean
lemo.mine.getMining().then(function(isMining) {
console.log(isMining ? 'mining' : 'not mining')
})
lemo.mine.getMiner()
Get the account address to receive mining benefit
None
Promise
- Call then
method to get account address
lemo.mine.getMiner().then(function(miner) {
console.log(miner) // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})
lemo.account.newKeyPair()
Create a private key and account address
None
Promise
- Call then
method to get account key object
const result = lemo.account.newKeyPair()
console.log(result.privateKey) // "0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52"
console.log(result.address) // "Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34"
lemo.account.getBalance(address)
Get the balance of an account
string
- account address
Promise
- Call then
method to get balance BigNumber
object
lemo.account.getBalance('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34').then(function(balance) {
console.log(balance.toString(10)) // "1600000000000000000000000000"
})
lemo.account.getAccount(address)
Get the information of an account
string
- account address
Promise
- Call then
method to get account information
lemo.account.getAccount('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34').then(function(account) {
console.log(account.balance.toMoney()) // "1600000000 LEMO"
})
lemo.account.getCandidateInfo(address)
Get the information of an candidate
string
- candidate account address
Promise
- Call then
method to get candidate information. It is same with candidate
in account
lemo.account.getCandidateInfo('Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34')
.then(function(candidate) {
console.log(candidate.votes); // "1599999000"
})
lemo.account.getVoteFor(address)
Get voting information from account
string
- lemo address
promise
- return a vote target address
lemo.account.getVoteFor('Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG')
.then(function(info) {
console.log(info); // "Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG"
})
lemo.account.getEquity(address, assetId)
Get the balance of asset from account
string
- The account addressstring
- asset id
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
lemo.account.getEquity('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', '0x34b04e018488f37f449193af2f24feb3b034c994cde95d30e3181403ac76528a')
.then(function(info) {
console.log(info.assetCode); // "0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884"
})
lemo.account.createTempAddress(from, userId)
create a temp account
string
- account addressstring
- customized user id, which's length should be 10 bytes in hexadecimal at most
string
- Temporary account address
const userId = '1110000000000000000'
const result = lemo.account.createTempAddress('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', userId)
console.log(result) // Lemo85SY56SGRTQQ63A2Y43KYA8C7QAZB37P3KY5
lemo.account.isTempAddress(address)
Test whether the specific address is a temporary account or not
string
- Account address
boolean
- True if the current address is a temporary account
const result = lemo.account.isTempAddress('Lemo85SY56SGRTQQ63A2Y43KYA8C7QAZB37P3KY5')
console.log(result) // true
lemo.account.isContractAddress(address)
Test whether the specific address is a contract account or not
string
- Account address
boolean
- True if the current address is a contract account
const result = lemo.account.isContractAddress('Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D')
console.log(result) // false
lemo.tx.send(txConfig, privateKey)
Send a transaction
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
Promise
- Call then
method to get transaction hash
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(txHash)
wait for the transaction to be confirmed
string
- transaction hash
Promise
- Call then
method to get transaction hash
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(filterTxConfig, callback)
Listen for transactions of block. Returns an array with transactions from block body, and the value of the subscribeId
object
- This is the condition used to filter the transactions, can enter multiple attributesfunction
- Used to receive transaction list
number
- subscribeId, it is used to stop watching
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(subscribeId)
Stop watching and filtering transactions of block
number
- The subscribeId from watchTx
None
const subscribeId = lemo.tx.watchTx({to:'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY'}, function(transactions) {
console.log(transactions[0].version)
});
lemo.tx.stopWatchTx(subscribeId)
lemo.stopWatch()
Stop all listening
None
None
lemo.stopWatch()
lemo.isWatching()
True if is listening
None
boolean
- True if is listening
console.log(lemo.isWatching() ? 'watching' : 'not watching')
LemoCore.SDK_VERSION
string
- The version of SDK
console.log(LemoCore.SDK_VERSION) // "1.0.0"
LemoCore.TxType
Enum of transaction type, the value is number
type
console.log(LemoCore.TxType.VOTE) // 1
LemoCore.ChangeLogType
Enum of change log type, the value is number
type
console.log(LemoCore.ChangeLogType.BalanceLog) // 1
- Node.js
- yarn
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install yarn
yarn build
yarn test
LGPL-3.0