lemo-tx v1.1.14
LemoTx
A tool for creating, manipulating and signing LemoChain transactions.
Installing
Using Yarn
yarn add lemo-txAs Browser module
- Include
lemo-tx.min.jsin your html file. - Use the
LemoTxobject directly from global namespace
Example
const LemoTx = require('lemo-tx')
const tx = new LemoTx({
chainID: 1,
from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D',
to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34',
amount: 100,
})
console.log(tx.toString())
// {"type":"0","version":"1","chainID":"1","from":"Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D","gasPrice":"3000000000","gasLimit":"2000000","amount":"100","expirationTime":"1566886054","to":"Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34","sigs":[],"gasPayerSigs":[]}LemoTx API
| API | description |
|---|---|
| new LemoTx(txInfo) | Create a transaction |
| tx.signWith(privateKey) | Sign transaction |
| tx.hash() | Calculate hash of the transaction |
| tx.toString() | Format transaction to json string |
| Static Properties | description |
|---|---|
| LemoTx.sign(privakey, txConfig) | Sign transaction |
| LemoTx.createVote(txInfo) | Create a special transaction for vote |
| LemoTx.createCandidate(txInfo, candidateInfo) | Create a special transaction for register/edit candidate |
| LemoTx.createAsset(txConfig, createAssetInfo) | Create a special transaction for create candidate |
| LemoTx.createIssueAsset(txConfig, issueAssetInfo) | Create a special transaction for the issuance of asset |
| LemoTx.createReplenishAsset(txConfig, replenishInfo) | Create a special transaction for replenish asset |
| LemoTx.createModifyAsset(txConfig, modifyInfo) | Create a special transaction for modify asset |
| LemoTx.createTransferAsset(txConfig, transferAssetInfo) | Create a special transaction for transfer asset |
| LemoTx.createNoGas(txConfig, gasPayer) | Create a special transaction for free gas |
| LemoTx.createReimbursement(noGasTxStr, gasPrice, gasLimit) | Create a special transaction for gas reimbursement |
| LemoTx.createCreateTempAddress(txConfig, userId) | Create a special transaction for create temp account |
| LemoTx.createModifySigners(txConfig, signer) | Create a special transaction for modify multiple signer |
| LemoTx.createBoxTx(txConfig, subTxList) | Create a special transaction for box transaction |
| LemoTx.createContractCreation(txConfig, code, constructorArgs) | Create a special transaction for contract creation |
| LemoTx.createPayDeepLink(txConfig) | Create deep links for payments |
| LemoTx.createSignDeepLink(config) | Create deep links for signatures |
| LemoTx.parseDeepLink(uri) | Parse deep link |
| LemoTx.TxType | Enum of transaction type |
| LemoTx.DeepLinkType | Enum of deep link |
Data structure
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 id.1for main net and100for dev netversionCurrent 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 |
|---|---|---|
| LemoTx.TxType.ORDINARY | 0 | Normal transaction or smart contract execution transaction |
| LemoTx.TxType.CREATE_CONTRACT | 1 | Create contract |
| LemoTx.TxType.VOTE | 2 | Set vote target |
| LemoTx.TxType.CANDIDATE | 3 | Register or modify candidate information |
| LemoTx.TxType.CREATE_ASSET | 4 | Create asset information |
| LemoTx.TxType.ISSUE_ASSET | 5 | Issue asset |
| LemoTx.TxType.REPLENISH_ASSET | 6 | Replenish asset transaction |
| LemoTx.TxType.MODIFY_ASSET | 7 | Modify asset transaction |
| LemoTx.TxType.TRANSFER_ASSET | 8 | Transfer assets |
| LemoTx.TxType.MODIFY_SIGNER | 9 | Modify account signers |
| LemoTx.TxType.BOX_TX | 10 | Package multiple transactions and run them transactional |
| chainID | description |
|---|---|
| 1 | LemoChain main net |
| 100 | LemoChain test net |
| transaction type | number value | description |
|---|---|---|
| LemoTx.TxType.PAY | 0 | The deeplink type of payment |
| LemoTx.TxType.SIGN | 1 | The deeplink type of the signature |
asset
Asset information
{
"category": "1",
"decimal": 18,
"totalSupply": "15000000000000000000",
"isReplenishable": true,
"isDivisible": true,
"issuer": "Lemo83GWNWJQ3DQFN6F24WFZF5TGQ39A696GJ7Z3",
"profile": {
"name": "Demo Asset",
"symbol": "DT",
"description": "this is a asset information",
"suggestedGasLimit": "60000",
"freeze": "false"
}
}categoryAsset typedecimalThe decimal place of the issued asset, which indicates how many digits are reduced to the decimal point. The default is 18 digits. Decimal cannot be greater than 18totalSupplyThe total amount of assets issued, when the assets are issued and destroyed, the total amount of assets will change in real time, the total amount of assets issued isissuance*10^decimalisReplenishableWhether the asset can be replenish. It is not changeable after setup when creating the asset. The default istrueisDivisibleWhether the asset is divisible, set when the asset is created, the default istrueissuerThe publisher address. It is not settableprofileAdditional information about the assetnameThe name of the assetsymbolAsset identificationdescriptionBasic information of assetssuggesteGasLimitSuggested gas limit. It is like thegasLimitfield in transaction. The default is 60000freezeWhether to freeze asset. The default is false. Set it to true will stop all actions about the asset except query operations
asset category
| category | description |
|---|---|
| 1 | TokenAsset. Similar to Ethereum's ERC20 token. The issuer can decide whether additional issuance is allowed in the future when issuing. The token is divisible. |
| 2 | NonFungibleAsset. Similar to Ethereum's ERC721 token, it can store a certain amount of information. Every token is indivisible. |
| 3 | CommonAsset. More flexible digital assets. It is suitable for more complex scenarios. Actualy, the TokenAsset and NonFungibleAsset are two special CommonAsset. |
tx API
Constructor transaction
tx = new LemoTx({
chainID: 1,
from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D',
to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34',
amount: 100,
})type- (number) (optional) Transaction type. Default value is0chainID- (number) The LemoChain id.1for main net and100for dev netversion- (number) (optional) Transaction encode version. Default value is0to- (string) (optional) Recipient address. Emptytorepresents a contract creation transaction with contract code indatafieldtoName- (string) (optional) Recipient name. It will be checked withtofor safeamount- (number|string) (optional) Amount inmo. Default value is0gasPrice- (number|string) (optional) Max gas limit of transaction. Default value is3000000000gasLimit- (number|string) (optional) Price of every gas inmo. Default value is2000000data- (Buffer|string) (optional) The extra data. It usually be using for calling smart contractexpirationTime- (number|string) (optional) The expiration time of transaction in seconds. Default is half hour from nowmessage- (string) (optional) Extra text message from sender
tx.signWith
tx.signWith(privateKey, txInfo)Sign transaction and return the signed transaction string
The API is used for implement safety offline transaction:
1. Sign transaction on a offline device
2. Copy the output string ( untamable ) to a online device
3. Call the send method in lemo-client to send the transaction to LemoChain
Parameters
string- Account private keyobject- Unsigned transaction like the same parameter intx constructor
Returns
string - The string of signed transaction information
Example
const tx = new LemoTx({from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100})
const signedTxStr = tx.signWith('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52')
console.log(signedTxStr.toString())
// {"type":"0","version":"1","chainID":"1","gasPrice":"3000000000","gasLimit":"2000000","amount":"100","expirationTime":"1560244840","from":"Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D","to":"Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34","sigs":["0x55fe70309bb74aaad62a7fe4ab4085dd8c8bd450ce9eab8dd7906cc5453cbaab500f50e1d05ff746248bc806f4738be2fcaafc78a557edf1e34c976a21d6f0c200"],"gasPayerSigs":[]}static API
LemoTx.sign
LemoTx.sign(privakey, txConfig)Sign transaction and return the signed transaction string
The API is used for implement safety offline transaction:
1. Sign transaction on a offline device
2. Copy the output string ( untamable ) to a online device
3. Call the send method in lemo-client to send the transaction to LemoChain
Parameters
string- Account private keyobject- Unsigned transaction
Returns
string - The string of signed transaction information
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100}
const code = '0x000000100000100'
const constructorArgs = '213313'
const unsignedTx = LemoTx.createContractCreation(txInfo, code, constructorArgs)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', unsignedTx)
console.log(signedTxStr) // {"type":"1","version":"1","chainID":"1","from":"Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D","gasPrice":"3000000000","gasLimit":"2000000","amount":"100","expirationTime":"1567152222","to":"Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34","data":"0x0000001000001003313","sigs":["0xd897e25a640dda2d56ecb986c7b4c0dc835fd5131a434a5f5ca0ee1cd9caf8dc292dc4cefc9242c41a6e7976e000d66113232ff347e4db963dbaf70896fb27de00"],"gasPayerSigs":[]}
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createVote
LemoTx.createVote(txInfo)Create an unsigned LemoTx instance for vote. The API fills some special information in the data filed in LemoTx instance
Parameters
object - Unsigned transaction like the same parameter in tx constructor. For this API, to means vote target. And amount, data fields will be ignored.
Returns
LemoTx - Unsigned LemoTx instance
Example
const txInfo = {from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34'}
const tx = LemoTx.crateVote(txInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createCandidate
LemoTx.createCandidate(txInfo, candidateInfo)Create an unsigned LemoTx instance for candidate. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,to,toName,amount,datafields will be ignored.object- Candidate information. It is same withcandidate.profilein account
Returns
LemoTx - Unsigned LemoTx instance
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const candidateInfo = {
isCandidate: true,
name: 'cross-chain-node',
teamName: 'lemo-tac-team',
minerAddress: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG',
nodeID: '0x5e3600755f9b512a65603b38e30885c98cbac70259c3235c9b3f42ee563b480edea351ba0ff5748a638fe0aeff5d845bf37a3b437831871b48fd32f33cd9a3c0',
host: '127.0.0.1',
port: '7001',
introduction: 'this is a demo',
email: 'abc@gmail.com',
}
const tx = LemoTx.createCandidate(txInfo, candidateInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createAsset
LemoTx.createAsset(txConfig, createAssetInfo)Create an unsigned LemoTx instance for create assets. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,to,amount,toNamefields will be ignored.object- Create of assets information.
Returns
LemoTx - Unsigned LemoTx instance, data contains the information for create the asset
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const createAssetInfo = {
category: 1,
decimal: 18,
isReplenishable: true,
isDivisible: true,
profile: {
name: 'Demo Asset',
symbol: 'DT',
description: 'demo asset',
suggestedGasLimit: '60000',
},
}
const tx = LemoTx.createAsset(txInfo, createAssetInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx) LemoTx.createIssueAsset
LemoTx.createIssueAsset(txConfig, issueAssetInfo)Create an unsigned LemoTx instance for the issuance of assets. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,to,toName,amount,datafields will be ignored.object- Transfer of assets information. includesassetCode,metaData,supplyAmountfield
Returns
LemoTx - Unsigned LemoTx instance, data contains the information for issue the asset
Example
const txInfo = {chainID: 1,to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const issueAssetInfo = {
assetCode: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
metaData: 'issue asset metaData',
supplyAmount: '100000',
}
const tx = LemoTx.createIssueAsset(txInfo, issueAssetInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createReplenishAsset
LemoTx.createReplenishAsset(txConfig, replenishInfo)Create an unsigned LemoTx instance for replenish assets. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,amountfield will be ignored.object- Replenish assets information. includesassetID,replenishAmountfields
Returns
LemoTx - Unsigned LemoTx instance, data contains the information for replenish the asset
Example
const txInfo = {chainID: 1, to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const replenishAssetInfo = {
assetCode: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
assetId: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
replenishAmount: '100000',
}
const tx = LemoTx.createReplenishAsset(txInfo, replenishAssetInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createModifyAsset
LemoTx.createModifyAsset(txConfig, modifyInfo)Create an unsigned LemoTx instance for modify assets. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,amount,to,toNamefields will be ignored.object- Assets modification information. It containsassetCodeandinfofields. Theinfocontains the fields you want to modify, such asname,symbol,description,freeze,suggestedGasLimit.
Returns
LemoTx - Unsigned LemoTx instance, data contains the information for modify the asset
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const ModifyAssetInfo = {
assetCode: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
updateProfile: {
name: 'Demo Asset',
symbol: 'DT',
description: 'demo asset',
},
}
const tx = LemoTx.createModifyAsset(txInfo, ModifyAssetInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createTransferAsset
LemoTx.createTransferAsset(txConfig, transferAssetInfo)Create an unsigned LemoTx instance for transaction assets. The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor.object- Transaction assets information. includesassetIDfield
Returns
LemoTx - Unsigned LemoTx instance, data contains the information for transfer the asset
Example
const txInfo = {chainID: 1, to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const transferAsset = {
assetId: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
transferAmount: '110000',
}
const tx = LemoTx.createTransferAsset(txInfo, transferAsset)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createNoGas
LemoTx.createNoGas(txConfig, gasPayer)Create an unsigned LemoTx instance for gas free transaction. The API fills some special information in the data filed in LemoTx instance
1. Create a gas free transaction with transaction information and gasPayer account address. The transaction information is exclude gasLimit and gasPrice field
2. Send the output string to gas gasPayer
3. The gasPayer sign the string with his private key, fill gasLimit and gasPrice field. Then return a final transaction string
4. Call the send method in lemo-client to send the transaction to LemoChain
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,gasLimit,gasPricefields will be ignored.string- The address of gas gasPayer account.
Returns
LemoTx - Unsigned LemoTx instance
Example
const txInfo = {chainID: 1, to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const gasPayer = 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'
const tx = LemoTx.createNoGas(txInfo, gasPayer)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)LemoTx.createReimbursement
LemoTx.createReimbursement(noGasTxStr, gasPrice, gasLimit)Create an unsigned LemoTx instance for paying gas to a free gas transaction. The API fills some special information in the data filed in LemoTx instance
Parameters
string- The string returned by thetx.signNoGasmethod, Seetx.signNoGasstring- Price of every gas inmo.string- Max gas limit of transaction.
Returns
LemoTx - Unsigned LemoTx instance
Example
const txInfo = {chainID: 1, to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const gasPayer = 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'
const noGasInfo = LemoTx.createNoGas(txInfo, gasPayer)
const tx = LemoTx.createReimbursement(noGasInfo, 2, 100)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createCreateTempAddress
LemoTx.createCreateTempAddress(txConfig, userId)Create an unsigned LemoTx instance for create temp account transaction. The API fills some special information in the data filed in LemoTx instance
1. Temp account has no private key and only can be signed by accounts in its signers
2. Temp account must be configured with Signers before using it
3. If the temp account already exists, the creation will be fail
Parameters
object- Unsigned transaction like the same parameter intx constructor.string- customized user id, which's length should be 10 bytes in hexadecimal at most
Returns
LemoTx - Unsigned LemoTx instance
Example
const userId = '0123456789'
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY'}
const tx = LemoTx.createTempAddress(txInfo, userId)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createModifySigners
LemoTx.createModifySigners(txConfig, signers)Create the transaction of the signers in the multi-signer account, the API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor.array- Modified multiple signers list containing the fieldsaddressandweight
Returns
LemoTx - Unsigned LemoTx instance
Example
const signers = [{
address: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D',
weight: 50,
}, {
address: 'Lemo83GN72GYH2NZ8BA729Z9TCT7KQ5FC3CR6DJG',
weight: 50,
}]
const txInfo = {chianID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const tx = LemoTx.createModifySigners(txInfo, signers)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createBoxTx
LemoTx.createBoxTx(txConfig, subTxList) Create an unsigned LemoTx instance for box transactions,
The API fills some special information in the data filed in LemoTx instance
1. Box transaction can store multiple signed transaction informations including special transactions, but cannot store box transactions
2. The timestamp of the box transaction is equal to the minimum timestamp of the child transaction in the box
3. The neutron in the box transactions will succeed or fail at the same time, if one of the sub-transaction does not succeed then all the transactions in the box trade will fail
4. The sub-transaction of the box transaction must be signed transaction
Parameters
object- Unsigned transaction like the same parameter intx constructor. For this API,tofields will be ignored.array- Signed transaction list. The item should by signed transaction string or object
Returns
LemoTx - Unsigned LemoTx instance
Example
const createTempAddressInfo = {from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83JW7TBPA7P2P6AR9ZC2WCQJYRNHZ4NJD4CY'}
const createTempAddress = LemoTx.createTempAddress(createTempAddressInfo, '0123456789')
const signTempAddress = LemoTx.sign(testPrivate, createTempAddress)
const transferAssetInfo = {to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}
const transferAsset = {
assetId: '0xd0befd3850c574b7f6ad6f7943fe19b212affb90162978adc2193a035ced8884',
transferAmount: '110000',
}
const createTransferAsset = LemoTx.createTransferAsset(transferAssetInfo, transferAsset)
const signTransferAsset = LemoTx.sign(testPrivate, createTransferAsset)
const subTxList = [signTempAddress, signTransferAsset]
const tx = LemoTx.createBoxTx({chainID: '1', from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D'}, subTxList)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createContractCreation
LemoTx.createContractCreation(txConfig, code, constructorArgs)Create an unsigned LemoTx instance for contract creation
The API fills some special information in the data filed in LemoTx instance
Parameters
object- Unsigned transaction like the same parameter intx constructor.string- The hexadecimal string of the contract codestring- The hexadecimal string of a parameter constructed in the contract
Returns
LemoTx - Unsigned LemoTx instance
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100}
const code = '0x000000100000100'
const constructorArgs = '213313'
const tx = LemoTx.createContractCreation(txInfo, code, constructorArgs)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)LemoTx.createPayDeepLink
LemoTx.createPayDeepLink(txConfig)Create a deep link for payment and convert the constructed transaction into a link address
Parameters
object- Unsigned transaction like the same parameter intx constructor.
Returns
string - The address of lemo://pay? link
Example
const txInfo = {chainID: 1, from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D', to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34', amount: 100}
const result = LemoTx.createPayDeepLink(txInfo)
console.log(result)
// lemo://pay?c=1&f=Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D&t=Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34&a=0.0000000000000001LemoTx.createSignDeepLink
LemoTx.createSignDeepLink(config)Create deep links for signatures
Parameters
object- transaction information before signature, includes:message- (string)(optional)Text to be signeddata- (string)(optional)The hexadecimal data string to be signed. It must begin with 0x. Ifmessageis set, thendatawill be ignoresigner- (string)(optional)The account address who has the right to signreceiver- (string)(optional)Send a POST request with a signature over HTTP to that address
Returns
string - The address of lemo://sign? link
Example
const config = {message: 'sign this message', signer: 'Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH', receiver: 'http://lemochain.com/a?b=c',}
const result = createSignDeepLink(config)
console.log(result)
// lemo://sign?m=c2lnbiB0aGlzIG1lc3NhZ2U&s=Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH&r=http%3A%2F%2Flemochain.com%2Fa%3Fb%3DcLemoTx.parseDeepLink
LemoTx.parseDeepLink(uri)Parse deep link
Parameters
string- Deep links that need to be resolved.
Returns
object - The result after parsing, It has two filed:
data - (object)Parsed object information
deepLinkType - (number)Type of deeplink,like the same parameter in deeplinkType
Example
// The result is transaction information
const deepLinkTx = 'lemo://pay?ty=0&c=200&v=1&f=Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D&t=Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH&tn=aa&gp=0.000000002&gl=100&a=0.000000000000000001&d=0x0c&e=1544584596&m=YWFh'
const resultTx = LemoTx.parseDeepLink(deepLinkTx)
console.log(resultTx)
// {"data":{"type":0,"version":1,"chainID":200,"from":"Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D","to":"Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH","toName":"aa","gasPrice":"2","gasLimit":100,"amount":"1","data":"0x0c","expirationTime":1544584596,"message":"aaa"},"deepLinkType":0}
// The parsing result is the signature information
const deepLinkSign = 'lemo://sign?m=c2lnbiB0aGlzIG1lc3NhZ2U&s=Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH&r=http%3A%2F%2Flemochain.com%2Fa%3Fb%3Dc'
const resultSign = LemoTx.parseDeepLink(deepLinkSign)
console.log(resultSign)
// {"data":{"message":"sign this message","signer":"Lemo846Q4NQCKJ2YWY6GHTSQHC7K24JDC7CPCWYH","receiver":"http://lemochain.com/a?b=c"},"deepLinkType":1}other API
LemoTx.TxType
LemoTx.TxTypeEnum of transaction type, the value is number type
Example
console.log(LemoTx.TxType.VOTE) // 1LemoTx.DeepLinkType
LemoTx.DeepLinkTypeEnum of deeplink type, the value is number type
Example
console.log(LemoTx.DeepLinkType.PAY) // 0Developing
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