【问题标题】:TypeError:无法读取未定义的属性(读取“eth”)
【发布时间】:2022-01-21 12:55:24
【问题描述】:
const  {web3js, myAccount} = require ('./utils')
const {bytecode} = require ('./contractartifact')

async function deploy() {
    web3js.eth.sendTransaction({
        from: myAccount.address,
        data: bytecode,
        gas: 800

    })
    .on('receipt', console.log)
}

deploy()

错误

C:\Users\giris\getter-setter\deploy.js:9
    web3js.eth.sendTransaction({
           ^

TypeError: Cannot read properties of undefined (reading 'eth')
    at deploy (C:\Users\giris\getter-setter\deploy.js:9:12)
    at Object.<anonymous> (C:\Users\giris\getter-setter\deploy.js:19:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

【问题讨论】:

    标签: blockchain ethereum solidity web3


    【解决方案1】:

    您的导入不正确:

    const {web3js, myAccount} = require ('./utils')
    

    应该是:

    const web3js = new Web3(Web3.givenProvider || "ws://localhost:8545");
    

    【讨论】:

    • 嘿,我现在收到这个错误 TypeError: The listener must be a function
    • 这是一个单独的问题和不同的问题。如果我的回答解决了您最初的问题,您介意接受吗?
    • 是的,你的答案是在某处解决了我的问题,但请你帮我解决这个错误
    猜你喜欢
    • 1970-01-01
    • 2021-11-26
    • 2021-11-24
    • 2021-12-20
    • 2021-11-27
    • 2021-12-04
    • 2021-12-09
    • 2021-12-06
    • 2022-01-13
    相关资源
    最近更新 更多