【问题标题】:TypeError: Cannot read properties of undefined (reading 'Contract')TypeError:无法读取未定义的属性(读取“合同”)
【发布时间】:2021-09-19 00:30:12
【问题描述】:

TypeError: Cannot read properties of undefined (reading 'Contract')

模块。

彩票反应/src/lottery.js:9

我在服务并转到浏览器时收到此错误

我的代码

import web3 from "web3";

const address = '0x------------------------------';


const abi = [{"constant":true,"inputs":[],"name":"manager","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"pickWinner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getPlayers","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"enter","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"players","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];


function test () {
    console.log(web3.eth); // throws undefined 
};

export default test; 

【问题讨论】:

    标签: reactjs ethereum solidity smartcontracts


    【解决方案1】:

    web3.eth 未定义。先尝试修复它。

    【讨论】:

    • 请问我该如何解决这个问题?我无法 console.log web3.eth 并且我成功部署了合约。
    • 你的意思是你不能console.log web3.eth?你完成console.log(web3.eth)了吗?
    • 我没有定义。我刚刚更新了我的问题以包含我的代码@Shivam
    【解决方案2】:

    我做了一个小改动来修复它

    更新web3.eth

    new web3().eth

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-22
      • 2021-11-26
      • 2021-11-24
      • 2021-12-20
      • 2021-11-27
      • 2022-01-21
      • 2021-12-04
      • 2021-12-09
      相关资源
      最近更新 更多