Laska.zil
class asscess to zilliqa network
Usage
const Laksa=require('laksa')
// or
import Laksa from 'laksa'
// initialize
const laksa=new Laksa('https://api-scilla.zilliqa.com')
laksa.zil.<{Method|Object|Class}>
Sub Classes
- Laksa.zil.messenger
Methods
- Laksa.zil.checkCode
- Laksa.zil.checkCodeTest
- Laksa.zil.createMessage
- Laksa.zil.createTransaction
- Laksa.zil.getBalance
- Laksa.zil.getBlockTransactionCount
- Laksa.zil.getBlockchainInfo
- Laksa.zil.getClientVersion
- Laksa.zil.getCode
- Laksa.zil.getDSBlockListing
- Laksa.zil.getDsBlock
- Laksa.zil.getGasEstimate
- Laksa.zil.getGasPrice
- Laksa.zil.getHashrate
- Laksa.zil.getLatestDsBlock
- Laksa.zil.getLatestTxBlock
- Laksa.zil.getNetworkId
- Laksa.zil.getNodeMining
- Laksa.zil.getNumTxnsDSEpoch
- Laksa.zil.getNumTxnsTxEpoch
- Laksa.zil.getProtocolVersion
- Laksa.zil.getSmartContractCode
- Laksa.zil.getSmartContractInit
- Laksa.zil.getSmartContractState
- Laksa.zil.getSmartContracts
- Laksa.zil.getTransaction
- Laksa.zil.getTransactionHistory
- Laksa.zil.getTransactionListing
- Laksa.zil.getTransactionReceipt
- Laksa.zil.getTxBlock
- Laksa.zil.getTxBlockListing
- Laksa.zil.isConnected
Sub Objects
- Laksa.zil.config
- Laksa.zil.clientVersion
- Laksa.zil.hashrate
- Laksa.zil.networkId
- Laksa.zil.nodeMining
- Laksa.zli.protocolVersion
Methods
checkCode
WARNING
This Method is not open tested yet
DO NOT use it.
checkCodeTest
WARNING
This Method is not open tested yet
DO NOT use it.
createMessage
WARNING
This Method is not open tested yet
DO NOT use it.
createTransaction
Create Transaction from Address to Address
TIP
There some important concepts needed to explain.
Before you start using this method,
we recommend you to read this guide first.
Typed
createTransaction(signedTransaction:object<T>, callback?: void)=> Promises<Error|string>;
parameters
object- required, a SIGNED transaction object,should usezil.util.createTransactionJsonto generate it first.key type required? reference/example description amount BNumyes BNumTransaction amount to be send code stringno scilla codeSmart Contract Code data stringno scilla dataData that evoked to the contract gasLimit numberyes GasLimitMaximum gas to be proccessd gasPrice numberyes GasPriceSender defined gas fee per unit nonce numberyes NonceSender's total Transaction count +1 pubKey stringyes PublicKeySender public key signature stringyes SignatureAn EC-Schnorr signature to this transaction to stringyes AddressAddress that transaction to be send version stringyes 0 The current version
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|string>return an transaction id if transaction is made, otherwise return Error.
usage
// suppose Laksa is initialized
const signedTransactionObject = {
amout: {
negative: 0,
words: Array(2),
length: 1,
red: null
},
code: "scilla code",
data: "[{'vname':'dummy','type':'String','value':'ASDF'}]",
gasLimit: 50,
gasPrice: 1,
nonce: 2,
pubKey: "0246e7178dc8253201101e18fd6f6eb9972451d121fc57aa2a06dd5c111e58dc6a",
signature:
"1ff6d491782466992fd90947663b7dc67e62dc989f71b7d5e081e6bba09eca379c76a8d040d60397c715ea4b7417329ce0a99dc5753eb29917cf428f0d1b366a",
to: "0000000000000000000000000000000000000000",
version: 0
};
// use callback to get the result
Laksa.zil.createTransaction(signedTransactionObject, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.createTransaction(signedTransactionObject).then(console.log);
getBalance
Get Balance for address
Typed
getBalance({ address: string }, callback?: void)=> Promises<Error|object<T>>;
parameters
object- required, see belowkey type required? example description address stringyes Addressaddress to query
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>balance object, otherwise Errornonce:number- current address's noncebalance:number- current address's balance
usage
//suppose Laksa is initialized
const address = "9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a";
// use callback to get the result
Laksa.zil.getBalance({ address: address }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getBalance({ address: address }).then(console.log);
getBlockTransactionCount
WARNING
This Method is not open tested yet
DO NOT use it.
getBlockchainInfo
Get detail info of current blockchain
Typed
getBlockchainInfo(callback?: void)=> Promises<Error|object<T>>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Return blockchain detail info object, otherwise Error,CurrentDSEpoch:string- to be implementedCurrentMiniEpoch:string- to be implementedDSBlockRate:number- to be implementedNumDSBlocks:string- to be implementedNumPeers:number- to be implementedNumTransactions:string- to be implementedNumTxBlocks:string- to be implementedNumTxnsDSEpoch:string- to be implementedNumTxnsTxEpoch:number- to be implementedShardingStructure:object<T>- to be implementedNumPeers:Array<number>- to be implemented
TransactionRate:number- to be implementedTxBlockRate:number- to be implemented
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.getBlockchainInfo((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getBlockchainInfo().then(console.log);
getClientVersion
WARNING
This Method is not open tested yet
DO NOT use it.
getCode
WARNING
This Method is not open tested yet
DO NOT use it.
getDSBlockListing
WARNING
This Method is not open tested yet
DO NOT use it.
getDsBlock
Get DSBlock info from BlockNumber
Typed
DSBlock({ blockNumber: string }, callback?: void)=> Promises<Error|object<T>>;
parameters
object- required, see belowkey type required? example description blockNumber stringyes BlockNumberblock number to query
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Block info,otherwise Errorheader:object<T>blockNum:string- to be implementeddifficulty:number- to be implementedleaderPubkey:string- to be implementedminerPubkey:string- to be implementednonce:string- to be implementedprevhash:string- to be implementedtimestamp:string- to be implemented
signature:string- to be implemented
usage
// // suppose Laksa is initialized
const blockNumber = "10799";
// use callback to get the result
Laksa.zil.getDsBlock({ blockNumber: blockNumber }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getDsBlock({ blockNumber: blockNumber }).then(console.log);
getGasEstimate
WARNING
This Method is not open tested yet
DO NOT use it.
getGasPrice
WARNING
This Method is not open tested yet
DO NOT use it.
getHashrate
WARNING
This Method is not open tested yet
DO NOT use it.
getLatestDsBlock
Returns the most recent DS block
Typed
getLatestDsBlock( callback?: void)=> Promises<Error|object<T>>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>DS Block Object,seegetDsBlock ,otherwise Error
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.getLatestDsBlock((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getLatestDsBlock().then(console.log);
getLatestTxBlock
Returns the most recent Tx block
Typed
getLatestTxBlock( callback?: void)=> Promises<Error|object<T>>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Tx Block Object,seegetTxBlock ,otherwise Error
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.getLatestTxBlock((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getLatestTxBlock().then(console.log);
getNetworkId
Get Nework Id of current Provider
Typed
getNetworkId(callback?: void)=> Promises<Error|string>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|string>Network Id string, otherwise Error
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.getNetworkId((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getNetworkId().then(console.log);
getNodeMining
Get current node mining status
Typed
getNodeMining(callback?: void)=> Promises<Error|boolean>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|boolean>Network mining status boolean, otherwise Error
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.getNodeMining((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getNodeMining().then(console.log);
getNumTxnsDSEpoch
WARNING
This Method is not open tested yet
DO NOT use it.
getNumTxnsTxEpoch
WARNING
This Method is not open tested yet
DO NOT use it.
getProtocolVersion
WARNING
This Method is not open tested yet
DO NOT use it.
getSmartContractCode
Get Smart Contract code from smart contract address
Typed
getSmartContractCode({ address: string }, callback?: void)=> Promises<Error|object<T>>;
parameters
object- required, see belowkey type required? example/reference description address stringyes AddressSmart Contract Address
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Return smart contract code object,otherwise Errorcode:string- scilla code string
usage
// suppose Laksa is initialized
const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";
// use callback to get the result
Laksa.zil.getSmartContractCode({ address: address }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getSmartContractCode({ address: address }).then(console.log);
getSmartContractInit
Returns the initialization parameters (immutable) of a given smart contract address
Typed
getSmartContractInit({ address: string }, callback?: void)=> Promises<Error|Array<T>>;
parameters
object- required, see belowkey type required? example description address stringyes AddressSmart Contract Address
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|Array<T>>Return smart contract init params array,otherwise ErrorTtype:string- to be implemented-value:string- to be implemented-vname:string- to be implemented-
usage
// suppose Laksa is initialized
const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";
// use callback to get the result
Laksa.zil.getSmartContractInit({ address: address }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getSmartContractInit({ address: address }).then(console.log);
getSmartContractState
Returns the state variables (mutable) of a given smart contract address
Typed
getSmartContractState({ address: string }, callback?: void)=> Promises<Error|Array<T>>;
parameters
object- required, see belowkey type required? example description address stringyes AddressSmart Contract Address
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|Array<T>>Return smart contract mutable params array,otherwise ErrorTtype:string- to be implemented-value:string- to be implemented-vname:string- to be implemented-
usage
// suppose Laksa is initialized
const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";
// use callback to get the result
Laksa.zil.getSmartContractState({ address: address }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getSmartContractState({ address: address }).then(console.log);
getSmartContracts
Return list of smart contracts from account address
Typed
getSmartContracts({ address: string }, callback?: void)=> Promises<Error|Array<T>>;
parameters
object- required, see belowkey type required? example description address stringyes {template} {template}
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|Array<T>>{template},otherwise ErrorTaddress:string- Smart Contract Addressstate:Array<T>- Smart Contract State, see getSmartContractState
usage
// suppose Laksa is initialized
const address = "4317141bd3f73b6807f874c3265603e8b69d53d5";
// use callback to get the result
Laksa.zil.getSmartContracts({ address: address }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getSmartContracts({ address: address }).then(console.log);
getTransaction
Return transaction detail object from transaction hash id
Typed
getTransaction({txHash:string}, callback?: void)=> Promises<Error|object<T>>;
parameters
object- required, see belowkey type required? example description txHash stringyes TxHashHash of transaction id
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Transaction object,otherwise ErrorTversion:string- the current versionnonce:string- Sender's nonce of this transactionto:string- Destination account addressfrom:string- Sender account addressamount:string- Transaction amountpubKey:string- PublicKey of the Sendersignature:string- An EC-Schnorr signature for this transaction
usage
// suppose Laksa is initialized
const txHash =
"ef80dab81656c14cde1f93864d38b16b059ffc7cf0457543561d4afe3ca20063";
// use callback to get the result
Laksa.zil.getTransaction({ txHash: txHash }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getTransaction({ txHash: txHash }).then(console.log);
getTransactionHistory
WARNING
This Method is not open tested yet
DO NOT use it.
getTransactionListing
WARNING
This Method is not open tested yet
DO NOT use it.
getTransactionReceipt
WARNING
This Method is not open tested yet
DO NOT use it.
getTxBlock
Returns information about a Transaction block by block number.
Typed
getTxBlock({ blockNumber: string }, callback?: void)=> Promises<Error|object<T>>;
parameters
object- required, see belowkey type required? example description blockNumber stringyes 73062 transaction block number
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|object<T>>Transaction block detail object,otherwise ErrorTbody- body objectHeaderSign:string- EC-Schnorr signatureMicroBlockEmpty:Array<number>- to be implementedMicroBlockHashes:Array<string>- to be implemented
header- header objectBlockNum:string- Block number or this transaction blockDSBlockNum:string- DS Block number of this transaction blockGasLimit:string- Gas Limit of this transaction blockMinerPubKey:string- Miner's public keyNumMicroBlocks:number- to be implementedNumTxns:number- to be implementedStateHash:string- to be implementedTimeStamp:string- to be implementedTxnHash:string- to be implementedprevBlockHash:string- to be implementedtype:number- to be implementedversion:number- to be implemented
usage
// suppose Laksa is initialized
const blockNumber = "73062";
// use callback to get the result
Laksa.zil.getTxBlock({ blockNumber: blockNumber }, (err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.getTxBlock({ blockNumber: blockNumber }).then(console.log);
getTxBlockListing
WARNING
This Method is not open tested yet
DO NOT use it.
isConnected
Check Provider is connected
Typed
isConnected(callback?: void)=> Promises<Error|boolean>;
parameters
function- optional, callback function, Error as the first parameter,normal result will be as the second parameter,see examples:
function callback(err: Error, data: any): void { if (err) { // do with error } // do with data }
returns
Promises<Error|boolean>Boolean of connection status,otherwise Error
usage
// suppose Laksa is initialized
// use callback to get the result
Laksa.zil.isConnected((err, data) => {
if (err) {
console.log(err);
}
console.log(data);
});
// use then to return Promises
Laksa.zil.isConnected().then(console.log);
Sub Objects
config
return config params
Typed
config :object<T>
params
no
return
object- version:
string, - defaultProviderUrl:
string, - defaultBlock:
string, - defaultAccount:
string
- version:
Usage
//suppose Laksa is initialized
Laksa.zil.config;
/**
{ version: '0.0.1',
defaultProviderUrl: 'http://localhost:4200',
defaultBlock: 'latest',
defaultAccount: undefined }
*/
clientVersion
WARNING
This Method is not open tested yet
DO NOT use it.
hashrate
WARNING
This Method is not open tested yet
DO NOT use it.
networkId
Get Nework Id of current Provider
Typed
networkId: Promises<Error|string>;
parameters
none
returns
Promises<Error|string>Network Id string, otherwise Error
usage
// suppose Laksa is initialized
// use then to return Promises
Laksa.zil.networkId.then(console.log);
nodeMining
Get current node mining status
Typed
nodeMining: Promises<Error|boolean>;
parameters
none
returns
Promises<Error|boolean>Network mining status boolean, otherwise Error
usage
// suppose Laksa is initialized
// use then to return Promises
Laksa.zil.nodeMining.then(console.log);
protocolVersion
WARNING
This Method is not open tested yet
DO NOT use it.