首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将Web3js导入到离子/角度项目中?

如何将Web3js导入到离子/角度项目中?
EN

Stack Overflow用户
提问于 2019-01-29 01:54:29
回答 1查看 1.7K关注 0票数 2

我尝试在我的离子v4项目中安装Web3已经有一段时间了。当我为项目服务时,它总是抛出错误。

这是我到目前为止所掌握的。我使用以下命令安装了web3

代码语言:javascript
复制
npm install --save web3

这就是使用它的服务看起来的样子,非常简单,仅用于测试。

代码语言:javascript
复制
import { Injectable } from '@angular/core';
import Web3 from 'web3';

@Injectable({
  providedIn: 'root'
})
export class Web3Service {

  constructor() { }

  web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/INFURA_API_KEY_HERE')); // removed api key for obvious reasons

  logThings() {
    console.log(this.web3);
  }
}

下面是我的package.json的样子:

代码语言:javascript
复制
{
  "name": "webb3",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^7.2.2",
    "@angular/core": "^7.2.2",
    "@angular/forms": "^7.2.2",
    "@angular/http": "^7.2.2",
    "@angular/platform-browser": "^7.2.2",
    "@angular/platform-browser-dynamic": "^7.2.2",
    "@angular/router": "^7.2.2",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.0.0",
    "@ionic/pro": "2.0.4",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "web3": "^1.0.0-beta.39",
    "zone.js": "~0.8.29"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.12.3",
    "@angular-devkit/build-angular": "~0.12.3",
    "@angular-devkit/core": "~7.2.3",
    "@angular-devkit/schematics": "~7.2.3",
    "@angular/cli": "~7.2.3",
    "@angular/compiler": "~7.2.2",
    "@angular/compiler-cli": "~7.2.2",
    "@angular/language-service": "~7.2.2",
    "@ionic/angular-toolkit": "~1.2.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^10.12.18",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~8.0.0",
    "tslint": "~5.12.0",
    "typescript": "~3.1.6"
  },
  "description": "An Ionic project"
}

下面是我得到的错误:

代码语言:javascript
复制
[ng] ERROR in node_modules/web3-bzz/types/index.d.ts(28,27): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
[ng] node_modules/web3-bzz/types/index.d.ts(30,60): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
[ng] node_modules/web3-core/types/index.d.ts(20,22): error TS2307: Cannot find module 'net'.
[ng] node_modules/web3-providers/types/index.d.ts(23,22): error TS2307: Cannot find module 'net'.
[ng] node_modules/web3-utils/types/index.d.ts(71,54): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
[ng] node_modules/web3-utils/types/index.d.ts(72,48): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try `npm i @types/node`.
[ng] node_modules/web3/types/index.d.ts(22,22): error TS2307: Cannot find module 'net'.
[ng]
[ng] i 「wdm」: Failed to compile.

我不完全确定我在这里做错了什么,所以任何帮助都是非常感谢的。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-31 02:58:39

嘿Rohan只是突然出现在这里看看有没有人有问题。我在github上看到了你的帖子和我为你解决的答案,所以如果有人有这个问题,请看:

https://github.com/ethereum/web3.js/issues/2260#issuecomment-458519127 -用于临时修复。

此问题的修复程序将在下一个版本中部署,PR为:

https://github.com/ethereum/web3.js/pull/2262

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54407665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档