Numerous settings are available when initialising the core API via Lisk-JS. Please see the examples below.
The provision of settings is optional, therefore initialising without any arguments var LSK = lisk.api();
yields the defaults.
var options = {
ssl: false, // Default false. Set to true to enable the https instead of http protocol.
node: '', // Default randomNode. Insert a node without http or https protocol. Use ssl option in order to set http or https.
randomPeer: true, // Default true. Lisk-js automatically connects to a random peer to get lisk blockchain information. Set to false to disable this behaviour.
testnet: true, // Default false. Set to true to use the testnet. Set to false to use the mainnet.
port: '7000', // Default 8000. Enter the port as the protocol http(s)://node:port - can be any string.
bannedPeers: [], // Default empty. Array of peers that should not be connected to. Without http(s) or port.
};
var LSK = lisk.api(options);
var options = {
ssl: false, // default false
node: 'localhost', // write node without http:// or port
randomPeer: false, // default true
testnet: false, // default false
port: '8000', // default 8000
bannedPeers: [], // default empty
};
var LSK = lisk.api(options);
lisk.api().getAccount(accountAddress, callback);
lisk.api().listActiveDelegates(5, callback);
lisk.api().listStandbyDelegates(6, callback);
lisk.api().searchDelegateByUsername('username', callback);
lisk.api().getBlock(blockId, callback);
lisk.api().listBlocks(amount, callback);
lisk.api().listForgedBlocks(publicKey, callback);
lisk.api().getTransaction(transactionId, callback);
lisk.api().listTransactions(address, limit, offset, callback);
Address: The Lisk address for recipient and sender of the transactions.
Limit: The number of transactions to retrieve. Minimum: 1, Maximum: 1000.
Offset: The number of records to offset the query from, e.g. a given offset of 10 excludes the first 10 records from the yielded results.
lisk.api().listVotes(address, callback);
lisk.api().listVoters(publicKey, callback);
lisk.api().listMultisignatureTransactions(callback);
lisk.api().getMultisignatureTransaction('transactionID', callback);
sendRequest
gives full access to the Lisk core API. It accepts any valid endpoint and parameters.
var liskBlockheight = lisk.api().sendRequest('blocks/getHeight', function (data) {
var str = JSON.stringify(data);
document.getElementById('output').innerHTML = str;
});
var liskNewAccount = lisk.api().sendRequest('accounts/open', { secret: 'my secret passphrase' }, function (data) {
var str = JSON.stringify(data);
document.getElementById('output').innerHTML = str;
});
The provided secret is intercepted and never transmitted over the network.
var LSK = lisk.api().getNethash();
{
'Content-Type': 'application/json',
'nethash': 'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511',
'broadhash': 'ed14889723f24ecc54871d058d98ce91ff2f973192075c0155ba2b7b70ad2511',
'os': 'lisk-js-api',
'version': '1.0.0',
'minVersion': '>=0.5.0',
'port': this.port
}
var LSK = lisk.api().setNode('mynode.com');
Use LSK.setNode();
without any arguments to automatically choose a new random node.
var LSK = lisk.api().listPeers();
Yields an object containing arrays of network categorised peers:
{ official: [...], ssl: [...], testnet: [...], localhost: [...] }
var LSK = lisk.api().setSSL(true); // or false
var LSK = lisk.api().setTestnet(true); // or false
var keys = lisk.crypto.getKeys('secret');
{
publicKey: '5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09',
privateKey: '2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a2…44491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09'
}
var keys = lisk.crypto.getAddress('5d036a858ce89f844491762eb89e2bfbd50a4a0a0da658e4b2628b25b117ae09');
18160565574430594874L
var transactionBytes = lisk.crypto.getBytes(transactionObject);
var transactionHash = lisk.crypto.getHash(transactionObject);
var transactionId = lisk.crypto.getId(transactionObject);
var transactionFee = lisk.crypto.getFee(transactionObject);
var transactionSignature = lisk.crypto.sign(transactionObject, keypair);
var transactionSignature = lisk.crypto.secondSign(transactionObject, keypair);
var transactionSignature = lisk.crypto.multiSign(transactionObject, keypair);
var keypair = lisk.crypto.getKeys(secret);
var verification = lisk.crypto.verify(transactionObject);
var verification = lisk.crypto.verifySecondSignature(transactionObject);
var bigAmount = lisk.crypto.fixedPoint(amount);
var hexString = lisk.crypto.bufferToHex(buffer);
var buffer = lisk.crypto.hexToBuffer(hexString);
Used to calculate unique identifiers.
var rawId = lisk.crypto.useFirstEightBufferEntriesReversed(buffer);
var messageSignature = lisk.crypto.signMessageWithSecret(message, secret);
var printSignedMessage = lisk.crypto.printSignedMessage(message, signedMessage, publicKey);
-----BEGIN LISK SIGNED MESSAGE-----
<message>
-----BEGIN SIGNATURE-----
<publicKey>
<signature>
-----END LISK SIGNED MESSAGE-----
In order maintain formatting it is advised to wrap the resulting output within a pre
tag.
Combines the signMessageWithSecret and printSignedMessage functions.
var printSignedMessage = lisk.crypto.printSignedMessage(message, secret);
Returns null if invalid, or the original message if valid.
var verifySignedMessage = lisk.crypto.verifyMessageWithPublicKey(signedMessage, publicKey);
Where message is a UTF-8 message, secret a passphrase and recipientPublicKey the publicKey in hex.
var encrypted = lisk.crypto.encryptMessageWithSecret(message, secret, recipientPublicKey);
{
encryptedMessage: encryptedMessage(hex),
nonce: nonce(hex)
}
Returns an object with the encrypted message and a nonce. Both are necessary in order to decrypt the message.
Where encrypted message is the hex format of the encrypted message, nonce also hex. The secret as the passphrase of the recipient and the sender publicKey in hex.
var encrypted = lisk.crypto.decryptMessageWithSecret(encryptedMessage, nonce, secret, senderPublicKey);
Original Message
If successfull, returns the plain text of the senders message.
var keypair = lisk.crypto.getPrivateAndPublicKeyFromSecret(secret);
{
publicKey: publicKey(hex),
privateKey: privateKey(hex)
}
var keypairBytes = lisk.crypto.getRawPrivateAndPublicKeyFromSecret(secret);
{
publicKey: publicKey(bytes),
privateKey: privateKey(bytes)
}
var address = lisk.crypto.getAddressFromPublicKey(publicKeyHex);
var sha256Hash = lisk.crypto.getSha256Hash(string);
var amount = 1000 * Math.pow(10, 8); // 100000000000
var transaction = lisk.transaction.createTransaction('1859190791819301L', amount, 'passphrase', 'secondPassphrase');
{
type: 0, // Transaction type. 0 = Normal transaction.
amount: 100000000000, // The amount to send expressed as an integer value.
asset: {}, // Transaction asset, dependent on tx type.
fee: 100000000, // 0.1 LSK expressed as an integer value.
id: '500224999259823996', // Transaction ID.
recipientId: '1859190791819301L', // Recipient ID.
senderPublicKey: '56e106a1d4a53dbe22cac52fefd8fc4123cfb4ee482f8f25a4fc72eb459b38a5', // Sender's public key.
signSignature: '03fdd33bed30270b97e77ada44764cc8628f6ad3bbd84718571695262a5a18baa37bd76a62dd25bc21beacd61eaf2c63af0cf34edb0d191d225f4974cd3aa509', // Sender's second passphrase signature.
signature: '9419ca3cf11ed2e3fa4c63bc9a4dc18b5001648e74522bc0f22bda46a188e462da4785e5c71a43cfc0486af08d447b9340ba8b93258c4c7f50798060fff2d709', // Transaction signature.
timestamp: 27953413 // Based on UTC time of genesis since epoch.
}
var transaction = lisk.vote.createVote('secret', ['+58199578191950019299181920120128129'], 'secondSecret');
var options = {
category: 0,
name: 'Lisk Guestbook',
description: 'The official Lisk guestbook',
tags: 'guestbook message sidechain',
type: 0,
link: 'https://github.com/MaxKK/guestbookDapp/archive/master.zip',
icon: 'https://raw.githubusercontent.com/MaxKK/guestbookDapp/master/icon.png'
};
var transaction = lisk.dapp.createDapp('secret', 'secondSecret', options);
var transaction = lisk.delegate.createDelegate('secret', 'username', 'secondSecret');
var transaction = lisk.signature.createTransaction('secret', 'secondSecret');
var secret = 'myprivatesecret';
var secondSecret = '';
var keysgroup = ['+publicKey1', '+publicKey2']; // Add publicKeys for multisignature.
var lifetime = 20; // Time in hours until transactions will be invalid.
var min = 2; // Minimum signatures so that a transaction is valid.
var transaction = lisk.multisignature.createMultisignature(secret, secondSecret, keysgroup, lifetime, min);
var signature = lisk.multisignature.signTransaction(transaction, secret);