@0bsnetwork/zbs-react 中文文档教程

发布于 5年前 浏览 22 更新于 3年前

zbs-react

用于与 0bsNetwork 交互的 React Native 库。 目前,实现的功能允许您执行以下操作;

  • 生成地址 - 这会为您的用户创建一个新钱包,并返回一个地址和一个种子短语。 您应该将种子短语存储在您的应用程序中(加密,用于生产),以便您可以将其用于未来的交易。 地址是你给用户的比特!

  • SaveData - 这将创建一个将数据保存到区块链的事务。 您可以使用它来将 json 对象保存到区块链。 作为回报,您将获得一个交易 ID,您可以使用该交易 ID 通过搜索交易 ID 在 https://explorer.0bsnetwork.com 上的区块链上查看数据。 您还可以将该 URL 用作永久链接,查看 URL 格式,如果您需要从您的应用程序链接到此以证明数据已保存。

  • sendTokens - 此方法允许您将 ZBS 硬币或另一个令牌(给定一个 assetId)转移到另一个地址,给定一个种子(因此是一个私钥)。

  • generateDocumentHash - 这会为上传的文件创建文档哈希,但目前仅在 Android 中实现,并且是实验性的。

Getting started

$ npm install 0bsnetwork/zbs-react --save

Mostly automatic installation

$ react-native link 0bsnetwork/zbs-react

For Android, Add below code in your app gradle file

android {
    defaultConfig {
        multiDexEnabled true
    }
}
IMPORTANT: when using `generateDocumentHash` function it's necessary to pass absolute file path and request permissions (on Android) to read on the external storage, here an example: [React Native Offical Doc] (https://facebook.github.io/react-native/docs/permissionsandroid)

Usage

GenerateAddress

import RN0bsnetwork from "zbs-react";

const response = await RN0bsnetwork.generateAddress();
      var responseData = JSON.parse(response);
      this.setState({ seed: responseData.seed, address: responseData.address });

saveData

import RN0bsnetwork from "zbs-react";

let dataArray = [
      {
        "type": "integer",
        "key": "integerVal",
        "value": 1
      },
      {
        "type": "boolean",
        "key": "booleanVal",
        "value": true
      },
      {
        "type": "string",
        "key": "stringVal",
        "value": "hello"
      }
]

let transfer = {data: dataArray, SEED_DATA: 'my long seed phrase ', NODE_URL: 'https://node1.testnet-0bsnetwork.com', assetId: '47dNzPs4KPFZchaahiDCLwsPSMsPDgy9CXfnutieHxMc'}

const transactionLog = await RN0bsnetwork.makeTransfer(transfer);

console.log(transactionLog);

sendTokens

import RN0bsnetwork from "zbs-react";

let transfer = {amount: 50, recipient:'3NBvF4xAGXJyrJNyS8B1yjrpBRdyT53MD6L', SEED_DATA: 'my long seed phrase ', NODE_URL: 'https://node1.testnet-0bsnetwork.com', assetId: '47dNzPs4KPFZchaahiDCLwsPSMsPDgy9CXfnutieHxMc'}

// Note: Exclude assetId to send ZBS.

const transactionLog = await RN0bsnetwork.makeTransfer(transfer);

console.log(transactionLog);

对于所有问题、问题或建议,提出问题或消息@justJamesDev在 Telegram 上或提出 PR,欢迎所有贡献!

zbs-react

A React Native library for interacting with 0bsNetwork. Currently, the functions implemented allow you to do the following;

  • Generate Addres - This creates a new wallet for your user, and returns an Address, and a Seed Phrase. You should store the seed phrase in your app (Encrypted, for production), so you can use it for future transactions. The address is the bit you give to the user!

  • SaveData - This creates a transaction that saves data to the blockchain. You can use this to save a json object to the blockchain. In return, you get a transaction ID that you can use to see the data once its on the blockchain at https://explorer.0bsnetwork.com by searching the transaction ID. You can also use that URL as a permalink, take a look at the URL format, should you need to link to this from your app to prove the data is saved.

  • sendTokens - This method allows you to transfer ZBS coin, or another token (Given an assetId) to another address, given a seed (Thus a private key).

  • generateDocumentHash - This creates a document hash for a file uploaded, however its currently only implemented in Android, and is experimental.

Getting started

$ npm install 0bsnetwork/zbs-react --save

Mostly automatic installation

$ react-native link 0bsnetwork/zbs-react

For Android, Add below code in your app gradle file

android {
    defaultConfig {
        multiDexEnabled true
    }
}
IMPORTANT: when using `generateDocumentHash` function it's necessary to pass absolute file path and request permissions (on Android) to read on the external storage, here an example: [React Native Offical Doc] (https://facebook.github.io/react-native/docs/permissionsandroid)

Usage

GenerateAddress

import RN0bsnetwork from "zbs-react";

const response = await RN0bsnetwork.generateAddress();
      var responseData = JSON.parse(response);
      this.setState({ seed: responseData.seed, address: responseData.address });

saveData

import RN0bsnetwork from "zbs-react";

let dataArray = [
      {
        "type": "integer",
        "key": "integerVal",
        "value": 1
      },
      {
        "type": "boolean",
        "key": "booleanVal",
        "value": true
      },
      {
        "type": "string",
        "key": "stringVal",
        "value": "hello"
      }
]

let transfer = {data: dataArray, SEED_DATA: 'my long seed phrase ', NODE_URL: 'https://node1.testnet-0bsnetwork.com', assetId: '47dNzPs4KPFZchaahiDCLwsPSMsPDgy9CXfnutieHxMc'}

const transactionLog = await RN0bsnetwork.makeTransfer(transfer);

console.log(transactionLog);

sendTokens

import RN0bsnetwork from "zbs-react";

let transfer = {amount: 50, recipient:'3NBvF4xAGXJyrJNyS8B1yjrpBRdyT53MD6L', SEED_DATA: 'my long seed phrase ', NODE_URL: 'https://node1.testnet-0bsnetwork.com', assetId: '47dNzPs4KPFZchaahiDCLwsPSMsPDgy9CXfnutieHxMc'}

// Note: Exclude assetId to send ZBS.

const transactionLog = await RN0bsnetwork.makeTransfer(transfer);

console.log(transactionLog);

For all issues, questions or suggestions, raise an issue or message @justJamesDev on Telegram or raise a PR, All contributions welcome!

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文