クイックスタート
JSLibの紹介

JSLibはライトウォレット開発者のためのnodejsライブラリです。JSLibを使えば、開発者はQurasブロックチェーンプラットフォームと簡単に相互作用することができます:

  • XQC/XQGを転送;
  • トークンをデプロイ/発行/転送
  • マルチシグアドレスをサポート;
  • ステーキング;

JSLibをインストールします:

npm install quras-js

JSLib ドキュメント: https://docs.quras.io/en/docs-overview.html

JSLibによるxqc/xqgトランザクションの実装方法

トランザクションを開始する前に、2点確認する必要があります:

  • 転送するXQC/XQGを保有していること;
  • 手数料として支払うためにXQGを保有していること(1日に1つのアドレスで3回まで手数料無料で取引することが可能);

下記ステップで、JSLibでXQC/XQGを転送することができます。

  • アドレスの残高データを取得;
  • 宛先アドレスのスクリプトハッシュを取得;
  • トランザクションの出力を設定;
  • 取引を構築し、署名;
  • トランザクションをブロードキャスト;

サンプルコード:

import * as Quras from 'quras-js'

  Quras.api.qurasDB.getBalance(Quras.CONST.QURAS_NETWORK.MAIN, 'DknmAbcap8RnUpkLQvbXTwTXqFJMjN4QPz') // Get the balance of from address.
  .then((data) => {
    const balance = new Quras.wallet.Balance(data)
    var scriptHash = Quras.wallet.getScriptHashFromAddress('Dqf3UKe1f5FBWduGxHp8RMqP29dL6DgGS1'); // To address.
    const outputs = [{
      assetId: Quras.CONST.ASSET_ID['XQC'], // The type of asset that you want to send.
      value: 2, // amount to send.
      fee: 0.2, // fee
      scriptHash: scriptHash // The scripthash of "To address".
    }]
    const testTx = Quras.tx.Transaction.createContractTx(balance, outputs) // create a transaction.
    testTx.sign('20164b85226c67cb6d8fe114f3b91af3f2dfc52dcf05d708e9eca80c8d739481'); // Sign the transaction using private key
    const rpcServer = new Quras.rpc.RPCClient(Quras.CONST.QURAS_NETWORK.MAIN);
    rpcServer.sendRawTransaction(testTx.serialize()) // Send the transaction to RPC Server.
      .then((data) => {
        console.log(data);
      })
      .catch ((error) => {
        console.log("error");
      });
  })
  .catch((error) => {
    console.log(error)
  });
XQGを報酬として請求する方法

アドレスがXQCを保有している場合、ステーキング報酬としてXQGを取得することができます(XQCの保有量による)。アドレスに報酬となるXQGを受け取るためトランザクションを実施できます。

この取引には、2つのステップが必要です:

  • 請求できる金額を確認する;
  • クレームトランザクションを構築し、ブロードキャストする;
import * as Quras from 'quras-js'
Quras.api.qurasDB.getClaimInfo(Quras.CONST.QURAS_NETWORK.MAIN, 'DknmAbcap8RnUpkLQvbXTwTXqFJMjN4QPz')
  .then((data) => {
    var testTx = Quras.tx.Transaction.createClaimTxWithQurasDB('DknmAbcap8RnUpkLQvbXTwTXqFJMjN4QPz', data['available']);

    testTx.sign('20164b85226c67cb6d8fe114f3b91af3f2dfc52dcf05d708e9eca80c8d739481'); // Sign the transaction using private key
    const rpcServer = new Quras.rpc.RPCClient(Quras.CONST.QURAS_NETWORK.MAIN);
    rpcServer.sendRawTransaction(testTx.serialize()) // Send the transaction to RPC Server.
      .then((data) => {
        console.log(data);
      })
      .catch ((error) => {
        console.log("error");
      });
  })
  .catch((error) => {
    console.log(error);
  });
                  
トークンをデプロイする

Qurasはカスタムトークンをサポートしており、どのユーザーもQurasプラットフォーム上で独自のトークンを発行することができます;

Qurasプラットフォームにトークンをデプロイするには、手数料として5000 XQGが必要です;

1.トークンをデプロイ:

import * as Quras from 'quras-js'
var assetData = new Array();
assetData['priKey'] = '02bf9e9964a3c0421ad5a8dde06f848977c514fd5cc638434d567a05b87ade39';
assetData['tokenName'] = 'DYKTest5';
assetData['totalSupply'] = 1000;
assetData['precision'] = 2;
assetData['afee'] = 0;
assetData['tfeeMin'] = 0;
assetData['tfeeMax'] = 10;

Quras.api.qurasDB.deployAsset(Quras.CONST.QURAS_NETWORK.MAIN, assetData)
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.log(error)
  })
                  

2.トークンを発行:

トークンを使用する前に、アドレスを発行する必要があります。

  • 残高データを取得;
  • ターゲットアドレスのスクリプトハッシュを取得;
  • トークントランザクションを作成発行し、署名;
  • トランザクションをブロードキャスト;
import * as Quras from 'quras-js'
Quras.api.qurasDB.getBalance(Quras.CONST.QURAS_NETWORK.MAIN, 'Do27ycn5urnJnWnNboiDh5i5PkAEFmvehd') // Get the balance of from address.
  .then((data) => {
    const balance = new Quras.wallet.Balance(data)
    var scriptHash = Quras.wallet.getScriptHashFromAddress('DrnEEnU1RtNKkP6TBAx8FaUQN1t1ghYPJV'); // To address.
    const outputs = [{
      assetId: '7a1a8c541de4fb7753d077a17870943b6a622817d922f46017d239f8db5b5bec', // The type of coins that you want to send.
      value: 1, // Coin amount to send.
      scriptHash: scriptHash // The scripthash of "To address".
    }]

    const testTx = Quras.tx.Transaction.createIssueTx(balance, outputs, null, 1) // create a transaction.

    testTx.sign('02bf9e9964a3c0421ad5a8dde06f848977c514fd5cc638434d567a05b87ade39'); // Sign the transaction using private key
    const rpcServer = new Quras.rpc.RPCClient(Quras.CONST.QURAS_NETWORK.MAIN);
    rpcServer.sendRawTransaction(testTx.serialize()) // Send the transaction to RPC Server.
      .then((data) => {
        console.log(data);
      })
      .catch ((error) => {
        console.log("error");
      });
  })
  .catch((error) => {
    console.log(error)
  });
                  

3.トークンを転送する:

トークン転送はXQC/XQG転送と同じで、「assetID」が違うだけです。

import * as Quras from 'quras-js'
Quras.api.qurasDB.getBalance(Quras.CONST.QURAS_NETWORK.MAIN, 'DknmAbcap8RnUpkLQvbXTwTXqFJMjN4QPz') // Get the balance of from address.
  .then((data) => {
    const balance = new Quras.wallet.Balance(data)
    var scriptHash = Quras.wallet.getScriptHashFromAddress('Dqf3UKe1f5FBWduGxHp8RMqP29dL6DgGS1'); // To address.
    const outputs = [{
      assetId: '7a1a8c541de4fb7753d077a17870943b6a622817d922f46017d239f8db5b5bec', // The type of asset that you want to send.
      value: 2, // amount to send.
      fee: 0.2, // fee
      scriptHash: scriptHash // The scripthash of "To address".
    }]
    const testTx = Quras.tx.Transaction.createContractTx(balance, outputs) // create a transaction.
    testTx.sign('20164b85226c67cb6d8fe114f3b91af3f2dfc52dcf05d708e9eca80c8d739481'); // Sign the transaction using private key
    const rpcServer = new Quras.rpc.RPCClient(Quras.CONST.QURAS_NETWORK.MAIN);
    rpcServer.sendRawTransaction(testTx.serialize()) // Send the transaction to RPC Server.
      .then((data) => {
        console.log(data);
      })
      .catch ((error) => {
        console.log("error");
      });
  })
  .catch((error) => {
    console.log(error)
  });
                  
Quras決済システムの統合方法

将来的にこの機能を追加します

Qurasについて Qurasスマートコントラクト