开发者问题收集

类型错误:无法读取未定义的属性(读取‘eth’)

2021-12-19
2481
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. (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

1个回答

此处导入不正确:

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

应为:

const web3js = new Web3(Web3.givenProvider || "ws://localhost:8545");
Dylan Kerler
2021-12-19