Laska.zil

访问 zilliqa network 的 Class

用法

const Laksa=require('laksa')
// 或者
import Laksa from 'laksa'

// 初始化
const laksa=new Laksa('https://api-scilla.zilliqa.com')

laksa.zil.*<{Method|Object|Class}>

Sub Classes

  • Laksa.zil.messenger

Methods

子对象


方法


checkCode

警告

这个方法还没有开放测试

不要 使用!


checkCodeTest

警告

这个方法还没有开放测试

不要 使用!


createMessage

警告

这个方法还没有开放测试

不要 使用!


createTransaction

从一个地址Address创建一个交易到Address,包括生成新的合约

TIP

这里有一些重要的概念需要做出解释.

在使用这个方法之前,

我们推荐你阅读 这篇指南

Typed

 createTransaction(signedTransaction:object<T>, callback?: void)=> Promises<Error|string>;

参数

    1. object- required, a SIGNED transaction object, should use zil.util.createTransactionJson to generate it first.

      键名 类型 必须? 索引/举例 说明
      amount BNum BNum 发送交易使用的 token 数
      code string scilla code 智能合约代码
      data string scilla data 与智能合约交互的数据
      gasLimit number GasLimit 交易可承受的最大 gas
      gasPrice number GasPrice 发送方支付的单元 gas
      nonce number Nonce 发送方的交易单计数器+1
      pubKey string PublicKey 发送方的公钥
      signature string Signature EC-Schnorr 签名
      to string Address 交易接收方地址
      version string 0 当前版本
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:

      function callback(err: Error, data: any): void {
        if (err) {
          // do with error
        }
        // do with data
      }
      

返回

  • Promises<Error|string> 如果交易成功发送,返回一个交易 id, 否则返回报错信息 Error.

使用

// 假设 Laksa 已经初始化

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
};

// 使用callback获取结果
Laksa.zil.createTransaction(signedTransactionObject, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.createTransaction(signedTransactionObject).then(console.log);

getBalance

通过地址获得帐号余额对象

Typed

 getBalance({ address: string }, callback?: void)=> Promises<Error|object<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      address string Address 需要查询的地址
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> 余额对象, 报错返回 Error
    • nonce: number- 当前地址的 nonce
    • balance: number - 当前地址的余额

用法

//假设 Laksa 已经初始化

const address = "9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a";

// 使用callback获取结果
Laksa.zil.getBalance({ address: address }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getBalance({ address: address }).then(console.log);

getBlockTransactionCount

警告

这个方法还没有开放测试

不要 使用!


getBlockchainInfo

获取 Blockchain 的详细信息

Typed

 getBlockchainInfo(callback?: void)=> Promises<Error|object<T>>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> 返回 Blockchain 信息对象,报错返回 Error,正常返回 true 或 false,
    • CurrentDSEpoch: string- 需要补充
    • CurrentMiniEpoch: string- 需要补充
    • DSBlockRate: number- 需要补充
    • NumDSBlocks: string- 需要补充
    • NumPeers: number- 需要补充
    • NumTransactions: string- 需要补充
    • NumTxBlocks: string- 需要补充
    • NumTxnsDSEpoch: string- 需要补充
    • NumTxnsTxEpoch: number- 需要补充
    • ShardingStructure: object<T>- 需要补充
      • NumPeers: Array<number>- 需要补充
    • TransactionRate: number- 需要补充
    • TxBlockRate: number- 需要补充

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.getBlockchainInfo((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getBlockchainInfo().then(console.log);

getClientVersion

警告

这个方法还没有开放测试

不要 使用!


getCode

警告

这个方法还没有开放测试

不要 使用!


getDSBlockListing

警告

这个方法还没有开放测试

不要 使用!


getDsBlock

通过 BlockNumber 获取 DS Block 详细信息

Typed

 DSBlock({ blockNumber: string }, callback?: void)=> Promises<Error|object<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      blockNumber string BlockNumber DS Block 的编号
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> DS Block 信息的对象,报错返回 Error
    • header:object<T>
      • blockNum:string- 待补充
      • difficulty:number- 待补充
      • leaderPubkey:string- 待补充
      • minerPubkey:string- 待补充
      • nonce:string- 待补充
      • prevhash:string- 待补充
      • timestamp:string- 待补充
    • signature:string- 待补充

用法

// 假设 Laksa 已经初始化

const blockNumber = "10799";

// 使用callback获取结果
Laksa.zil.getDsBlock({ blockNumber: blockNumber }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getDsBlock({ blockNumber: blockNumber }).then(console.log);

getGasEstimate

警告

这个方法还没有开放测试

不要 使用!


getGasPrice

警告

这个方法还没有开放测试

不要 使用!


getHashrate

警告

这个方法还没有开放测试

不要 使用!


getLatestDsBlock

获取最新的 DS Block 信息

Typed

 getLatestDsBlock(callback?: void)=> Promises<Error|object<T>>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> DS block 对象,见getDsBlock,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.getLatestDsBlock((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getLatestDsBlock().then(console.log);

getLatestTxBlock

获取最新的 Tx Block 信息

Typed

 getLatestTxBlock(callback?: void)=> Promises<Error|object<T>>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> Tx block 对象,见getTxBlock,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.getLatestTxBlock((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getLatestTxBlock().then(console.log);

getNetworkId

获取当前 Provider 的网络 ID

Typed

 getNetworkId(callback?: void)=> Promises<Error|string>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|string> 当前 Provider 的网络 ID 字符串,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.getNetworkId((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getNetworkId().then(console.log);

getNodeMining

获取当前节点挖矿状态,返回 boolean

Typed

 getNodeMining(callback?: void)=> Promises<Error|boolean>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|boolean> 当前节点挖矿状态,返回 boolean,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.getNodeMining((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getNodeMining().then(console.log);

getNumTxnsDSEpoch

警告

这个方法还没有开放测试

不要 使用!


getNumTxnsTxEpoch

警告

这个方法还没有开放测试

不要 使用!


getProtocolVersion

警告

这个方法还没有开放测试

不要 使用!


getSmartContractCode

通过合约地址获取智能合约代码

Typed

 getSmartContractCode({ address: address}, callback?: void)=> Promises<Error|object<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      address type Address 已部署的智能合约地址
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> 智能合约代码,字符串,报错返回 Error
    • code:string - 智能合约 scilla 代码

用法

// 假设 Laksa 已经初始化

const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";

// 使用callback获取结果
Laksa.zil.getSmartContractCode({ address: address }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getSmartContractCode({ address: address }).then(console.log);

getSmartContractInit

获取 Smartcontra 的初始化参数

Typed

 getSmartContractInit({ address: string }, callback?: void)=> Promises<Error|Array<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      address string Address 已部署的智能合约地址
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|Array<T>> 返回智能合约的初始化参数列表,报错返回 Error
    • T
      • type: string - 待补充-
      • value: string - 待补充-
      • vname: string - 待补充-

用法

// 假设 Laksa 已经初始化

const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";

// 使用callback获取结果
Laksa.zil.getSmartContractInit({ address: address }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getSmartContractInit({ address: address }).then(console.log);

getSmartContractState

获取 Smartcontra 的状态参数(可变变量)

Typed

 getSmartContractState({ address: string }, callback?: void)=> Promises<Error|Array<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      address string Address 已部署的智能合约地址
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|Array<T>> 返回智能合约的状态变量参数列表,报错返回 Error
    • T
      • type: string - 待补充-
      • value: string - 待补充-
      • vname: string - 待补充-

用法

// 假设 Laksa 已经初始化

const address = "38149f1bf4160c73c8cac49d8eeed44c3fb86ab4";

// 使用callback获取结果
Laksa.zil.getSmartContractState({ address: address }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getSmartContractState({ address: address }).then(console.log);

getSmartContracts

通过帐号地址获取其部署的智能合约列表

Typed

 getSmartContracts({ address: address}, callback?: void)=> Promises<Error|Array<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      address string Address 帐号地址
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|Array<T>> 返回智能合约列表,报错返回 Error

用法

// 假设 Laksa 已经初始化

const address = "4317141bd3f73b6807f874c3265603e8b69d53d5";

// 使用callback获取结果
Laksa.zil.getSmartContracts({ address: address }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getSmartContracts({ address: address }).then(console.log);

getTransaction

通过交易 HashID 获取交易详细信息

Typed

 getTransaction({txHash: string}, callback?: void)=> Promises<Error|boolean|string|number|any|object<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      txHash string yes TxHash 交易的 HashId
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> {文字模板},报错返回 Error
  • T
    • version:string - 当前版本
    • nonce:string - 发送方在当前交易的 nonce
    • to:string - 接受方地址
    • from:string - 发送方帐号地址
    • amount:string - 交易数量
    • pubKey:string - 发送方的公钥
    • signature:string- 交易的 EC-Schnorr 签名

用法

// 假设 Laksa 已经初始化

const txHash =
  "ef80dab81656c14cde1f93864d38b16b059ffc7cf0457543561d4afe3ca20063";

// 使用callback获取结果
Laksa.zil.getTransaction({ txHash: txHash }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getTransaction({ txHash: txHash }).then(console.log);

getTransactionHistory

警告

这个方法还没有开放测试

不要 使用!


getTransactionListing

警告

这个方法还没有开放测试

不要 使用!


getTransactionReceipt

警告

这个方法还没有开放测试

不要 使用!


getTxBlock

通过 BlockNumber 获取 Tx Block 的信息

Typed

 getTxBlock({ blockNumber: string }, callback?: void)=> Promises<Error|object<T>>;

参数

    1. object- 必须, 见下表

      键名 类型 必须 实例 描述
      blockNumber string yes 73062 transaction block number
    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|object<T>> TxBlock 对象,报错返回 Error
    • T
      • body - body 对象
        • HeaderSign:string - EC-Schnorr 签名
        • MicroBlockEmpty:Array<number> - to be implemented
        • MicroBlockHashes:Array<string>- to be implemented
      • header - header 对象
        • BlockNum:string - TxBlock 的编号
        • DSBlockNum:string - DS Block 的编号
        • GasLimit:string - TxBlock 含有的 Gas Limit
        • MinerPubKey:string - 矿工的公钥
        • NumMicroBlocks:number - 待补充
        • NumTxns:number - 待补充
        • StateHash:string - 待补充
        • TimeStamp:string - 待补充
        • TxnHash:string - 待补充
        • prevBlockHash:string - 待补充
        • type:number - 待补充
        • version:number - 待补充

用法

// 假设 Laksa 已经初始化

const blockNumber = "73062";

// 使用callback获取结果
Laksa.zil.getTxBlock({ blockNumber: blockNumber }, (err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.getTxBlock({ blockNumber: blockNumber }).then(console.log);

getTxBlockListing

警告

这个方法还没有开放测试

不要 使用!


isConnected

检查当前 Provider 连接状态

Typed

 isConnected(callback?: void)=> Promises<Error|boolean>;

参数

    1. function- 可选, 回调函数, 第一个参数为 Error 对象,第二个参数为正常返回结果,建议格式如下:
    function callback(err: Error, data: any): void {
      if (err) {
        // do with error
      }
      // do with data
    }
    

返回

  • Promises<Error|boolean> 当前 Provider 连接状态,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用callback获取结果
Laksa.zil.isConnected((err, data) => {
  if (err) {
    console.log(err);
  }
  console.log(data);
});

// 使用then返回Promises
Laksa.zil.isConnected().then(console.log);

子对象


config

返回当前的 config 参数

Typed

config :object<T>

参数

返回

  • object
    • version: string,
    • defaultProviderUrl: string,
    • defaultBlock: string,
    • defaultAccount: string

用法

//假设 Laksa 已经初始化
Laksa.zil.config;

/**
{ version: '0.0.1',
  defaultProviderUrl: 'http://localhost:4200',
  defaultBlock: 'latest',
  defaultAccount: undefined }
 */

clientVersion

警告

这个方法还没有开放测试

不要 使用!


hashrate

警告

这个方法还没有开放测试

不要 使用!


networkId

获取当前 Provider 的网络 ID

Typed

 networkId: Promises<Error|string>;

参数

返回

  • Promises<Error|string> 当前 Provider 的网络 ID 字符串,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用then返回Promises
Laksa.zil.networkId.then(console.log);

nodeMining

获取当前节点挖矿状态,返回 boolean

Typed

 nodeMining: Promises<Error|boolean>;

参数

返回

  • Promises<Error|boolean> 当前节点挖矿状态,返回 boolean,报错返回 Error

用法

// 假设 Laksa 已经初始化

// 使用then返回Promises
Laksa.zil.nodeMining.then(console.log);

protocolVersion

警告

这个方法还没有开放测试

不要 使用!