在NuxtJS项目中,无法在for循环内调用智能合约函数。每当我尝试在for循环外调用时,效果都很好。我在做什么错了?
let listOf = this.contract
const contractAddress = await this.cont.methods.contracts(2).call({
from: this.ethAddress
})
console.log("contract address in 2 index " + contractAddress) // it worrks
await this.contract.methods.getContractcount().call({
from: this.ethAddress
},
function (error, result) {
if (!error) {
var log = result
console.log(log)
var ContractList = async (log) => {
for (var i = 0; i < log; i++) {
console.log("==== " + i)
await listOf.methods.contracts(i).call({
from: this.ethAddress
})
.then(function (result) {
console.log(result) // it says error
});
}
}
ContractList(log)
} else {
console.log(error)
}
})
我的控制台错误
8d1bc033c0b40cc14af6.js:2 Uncaught (in promise) TypeError: Cannot read property 'startsWith' of undefined
at Function.t.fromHexString (8d1bc033c0b40cc14af6.js:2)
at t._callStaticAsync (8d1bc033c0b40cc14af6.js:2)
at t.<anonymous> (8d1bc033c0b40cc14af6.js:2)
at 8d1bc033c0b40cc14af6.js:2
at Object.next (8d1bc033c0b40cc14af6.js:2)
at 8d1bc033c0b40cc14af6.js:2
at new Promise (<anonymous>)
at Module.y (8d1bc033c0b40cc14af6.js:2)
at t._ethCall (8d1bc033c0b40cc14af6.js:2)
at t.<anonymous> (8d1bc033c0b40cc14af6.js:2)