【问题标题】:web3 with NativeScript带有 NativeScript 的 web3
【发布时间】:2019-01-17 20:32:06
【问题描述】:

如何在 NativeScript 中使用 web3.js 库(用于以太坊开发)?

我试过了:

  • 通过npm install web3@0.20.7 --save安装web3
  • 通过 Sidekick 中的插件管理器安装 web3
  • 甚至尝试过const Web3 =require('https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js');
  • 还尝试了const Web3 = require("./web3.min.js"); 与文件夹中的 web3.min.js 文件,但随后 console.log(Web3) 只打印一个空数组。

另外,我添加了 NativeScript 插件 nativescript-nodeify

在前三种情况下,我得到一个异常(除其他外)“调用 js 方法 onCreate 失败”

注意:我明确不想通过后端处理与以太坊的交互

【问题讨论】:

  • 你有没有找到解决这个问题的方法?我也想做同样的事情。
  • 您可以在 webview 中使用 web3,使用 @nota/nativescript-webview-ext 以便您可以在 webview 和您的 nativescript 代码之间来回通信。 (我已经像这样使用它并且对我来说效果很好)

标签: nativescript ethereum web3js nativescript-plugin


【解决方案1】:

我确实无法让 web3js 与 NativeScript 一起工作。看起来不可能,例如 web3 将使用浏览器与元掩码进行通信。

神经紧张,可能有一个解决方案,使用 eth.js :

// in your root project directory
// NOT with nativescript sidekick !
npm install --save ethjs
tns plugin add nativescript-nodeify

// then, in your code
require("nativescript-nodeify");
const Eth = require('ethjs');

然后,您可以与以太坊区块链进行交互。

编辑:TNS 插件名称是 nativescript-nodeify

【讨论】:

    猜你喜欢
    • 2019-12-04
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    相关资源
    最近更新 更多