javascript - 如何使用 ethereumjs-tx | 没有错误:Tx 不是构造函数?
问题描述
我正在尝试包含 etheruemjs-tx 浏览器构建,以便在我的浏览器上使用它来签署交易。它不断抛出错误“Tx 不是构造函数”
const Tx = "https://github.com/ethereumjs/browser-builds/blob/master/dist/ethereumjs-tx/ethereumjs-tx-1.3.3.js";
在我的终端上一切正常,因为我刚刚使用
const Tx = require('ethereumjs-tx').Transaction
但由于我不能在我的 javascript 代码上使用 require(),所以我一直在尝试各种方法,但我无法让它工作。单击按钮后,在我的浏览器控制台上,它转到此行..
const tx = new Tx(txObject,{chain: 'ropsten', hardfork: 'petersburg'})
错误是:(index):368 Uncaught TypeError: Tx is not a constructor
非常感谢有关如何在浏览器中使用 ethereumjs-tx 的帮助。
解决方案
在新版本中,您应该更改:
const Tx = require('ethereumjs-tx')
至
const Tx = require('ethereumjs-tx').Transaction
推荐阅读
- asp.net-mvc - 如何更改 asp.net core mvc 中的默认 AntiForgeryToken 标识符?
- r - Broom::augment() :有没有办法自定义列名或指定输出列?
- mongodb - 如何获取列表包含所有查询元素的文档
- ruby-on-rails - 数字海洋管理 sidekiq 工作者
- python - 如何根据pyspark数据框中的某些条件获取列名作为withColumn语句的一部分?
- google-apps-script - 用于将 ss 转换为多个不同 .pdf 文件的应用程序脚本
- microsoft-graph-api - 获取空状态码获取附件
- javascript - 使用 javascript .filter() 删除重复对象
- matlab - 在matlab中重新编码多维数组的元素
- jmeter - 如何在 Jmeter 中为请求设置随机间隔?