A tool for creating, manipulating and signing LemoChain transactions.
yarn add lemo-tx
- Include
lemo-tx.min.js
in your html file. - Use the
LemoTx
object directly from global namespace
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":[]}
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 |
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 id.1
for main net and100
for dev netversion
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 |
---|---|---|
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 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"
}
}
category
Asset typedecimal
The 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 18totalSupply
The 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^decimal
isReplenishable
Whether the asset can be replenish. It is not changeable after setup when creating the asset. The default istrue
isDivisible
Whether the asset is divisible, set when the asset is created, the default istrue
issuer
The publisher address. It is not settableprofile
Additional information about the assetname
The name of the assetsymbol
Asset identificationdescription
Basic information of assetssuggesteGasLimit
Suggested gas limit. It is like thegasLimit
field in transaction. The default is 60000freeze
Whether to freeze asset. The default is false. Set it to true will stop all actions about the asset except query operations
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 = new LemoTx({
chainID: 1,
from: 'Lemo836BQKCBZ8Z7B7N4G4N4SNGBT24ZZSJQD24D',
to: 'Lemo83BYKZJ4RN4TKC9C78RFW7YHW6S87TPRSH34',
amount: 100,
})
type
- (number) (optional) Transaction type. Default value is0
chainID
- (number) The LemoChain id.1
for main net and100
for dev netversion
- (number) (optional) Transaction encode version. Default value is0
to
- (string) (optional) Recipient address. Emptyto
represents a contract creation transaction with contract code indata
fieldtoName
- (string) (optional) Recipient name. It will be checked withto
for safeamount
- (number|string) (optional) Amount inmo
. Default value is0
gasPrice
- (number|string) (optional) Max gas limit of transaction. Default value is3000000000
gasLimit
- (number|string) (optional) Price of every gas inmo
. Default value is2000000
data
- (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(privateKey, txInfo)
Sign transaction and return the signed transaction string
The API is used for implement safety offline transaction:
- Sign transaction on a offline device
- Copy the output string ( untamable ) to a online device
- Call the send method in
lemo-client
tosend
the transaction to LemoChain
string
- Account private keyobject
- Unsigned transaction like the same parameter intx constructor
string
- The string of signed transaction information
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":[]}
LemoTx.sign(privakey, txConfig)
Sign transaction and return the signed transaction string
The API is used for implement safety offline transaction:
- Sign transaction on a offline device
- Copy the output string ( untamable ) to a online device
- Call the send method in
lemo-client
tosend
the transaction to LemoChain
string
- Account private keyobject
- Unsigned transaction
string
- The string of signed transaction information
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(txInfo)
Create an unsigned LemoTx instance
for vote. The API fills some special information in the data
filed in LemoTx instance
object
- Unsigned transaction like the same parameter in tx constructor
. For this API, to
means vote target. And amount
, data
fields will be ignored.
LemoTx
- Unsigned LemoTx instance
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(txInfo, candidateInfo)
Create an unsigned LemoTx instance
for candidate. The API fills some special information in the data
filed in LemoTx instance
object
- Unsigned transaction like the same parameter intx constructor
. For this API,to
,toName
,amount
,data
fields will be ignored.object
- Candidate information. It is same withcandidate.profile
in account
LemoTx
- Unsigned LemoTx instance
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: '[email protected]',
}
const tx = LemoTx.createCandidate(txInfo, candidateInfo)
const signedTxStr = LemoTx.sign('0xfdbd9978910ce9e1ed276a75132aacb0a12e6c517d9bd0311a736c57a228ee52', tx)
// Call the send method in lemo-client, lemo.send(signTx)
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
object
- Unsigned transaction like the same parameter intx constructor
. For this API,to
,amount
,toName
fields will be ignored.object
- Create of assets information.
LemoTx
- Unsigned LemoTx instance, data
contains the information for create the asset
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(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
object
- Unsigned transaction like the same parameter intx constructor
. For this API,to
,toName
,amount
,data
fields will be ignored.object
- Transfer of assets information. includesassetCode
,metaData
,supplyAmount
field
LemoTx
- Unsigned LemoTx instance, data
contains the information for issue the asset
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(txConfig, replenishInfo)
Create an unsigned LemoTx instance
for replenish assets. The API fills some special information in the data
filed in LemoTx instance
object
- Unsigned transaction like the same parameter intx constructor
. For this API,amount
field will be ignored.object
- Replenish assets information. includesassetID
,replenishAmount
fields
LemoTx
- Unsigned LemoTx instance, data
contains the information for replenish the asset
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(txConfig, modifyInfo)
Create an unsigned LemoTx instance
for modify assets. The API fills some special information in the data
filed in LemoTx instance
object
- Unsigned transaction like the same parameter intx constructor
. For this API,amount
,to
,toName
fields will be ignored.object
- Assets modification information. It containsassetCode
andinfo
fields. Theinfo
contains the fields you want to modify, such asname
,symbol
,description
,freeze
,suggestedGasLimit
.
LemoTx
- Unsigned LemoTx instance, data
contains the information for modify the asset
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(txConfig, transferAssetInfo)
Create an unsigned LemoTx instance
for transaction assets. The API fills some special information in the data
filed in LemoTx instance
object
- Unsigned transaction like the same parameter intx constructor
.object
- Transaction assets information. includesassetID
field
LemoTx
- Unsigned LemoTx instance, data
contains the information for transfer the asset
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(txConfig, gasPayer)
Create an unsigned LemoTx instance
for gas free transaction. The API fills some special information in the data
filed in LemoTx instance
- Create a gas free transaction with transaction information and
gasPayer
account address. The transaction information is excludegasLimit
andgasPrice
field - Send the output string to gas gasPayer
- The gasPayer sign the string with his private key, fill
gasLimit
andgasPrice
field. Then return a final transaction string - Call the send method in
lemo-client
tosend
the transaction to LemoChain
object
- Unsigned transaction like the same parameter intx constructor
. For this API,gasLimit
,gasPrice
fields will be ignored.string
- The address of gas gasPayer account.
LemoTx
- Unsigned LemoTx instance
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(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
string
- The string returned by thetx.signNoGas
method, Seetx.signNoGas
string
- Price of every gas inmo
.string
- Max gas limit of transaction.
LemoTx
- Unsigned LemoTx instance
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(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
- Temp account has no private key and only can be signed by accounts in its
signers
- Temp account must be configured with Signers before using it
- If the temp account already exists, the creation will be fail
object
- Unsigned transaction like the same parameter intx constructor
.string
- customized user id, which's length should be 10 bytes in hexadecimal at most
LemoTx
- Unsigned LemoTx instance
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(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
object
- Unsigned transaction like the same parameter intx constructor
.array
- Modified multiple signers list containing the fieldsaddress
andweight
LemoTx
- Unsigned LemoTx instance
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(txConfig, subTxList)
Create an unsigned LemoTx instance
for box transactions,
The API fills some special information in the data
filed in LemoTx instance
- Box transaction can store multiple signed transaction informations including special transactions, but cannot store box transactions
- The timestamp of the box transaction is equal to the minimum timestamp of the child transaction in the box
- 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
- The sub-transaction of the box transaction must be signed transaction
object
- Unsigned transaction like the same parameter intx constructor
. For this API,to
fields will be ignored.array
- Signed transaction list. The item should by signed transaction string or object
LemoTx
- Unsigned LemoTx instance
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(txConfig, code, constructorArgs)
Create an unsigned LemoTx instance
for contract creation
The API fills some special information in the data
filed in LemoTx instance
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
LemoTx
- Unsigned LemoTx instance
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(txConfig)
Create a deep link for payment and convert the constructed transaction into a link address
object
- Unsigned transaction like the same parameter intx constructor
.
string
- The address of lemo://pay?
link
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.0000000000000001
LemoTx.createSignDeepLink(config)
Create deep links for signatures
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. Ifmessage
is set, thendata
will 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
string
- The address of lemo://sign?
link
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%3Dc
LemoTx.parseDeepLink(uri)
Parse deep link
string
- Deep links that need to be resolved.
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
// 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}
LemoTx.TxType
Enum of transaction type, the value is number
type
console.log(LemoTx.TxType.VOTE) // 1
LemoTx.DeepLinkType
Enum of deeplink type, the value is number
type
console.log(LemoTx.DeepLinkType.PAY) // 0
- Node.js
- yarn
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install yarn
yarn build
yarn test
LGPL-3.0