【发布时间】:2018-05-17 09:38:02
【问题描述】:
let batch = new this.web3.BatchRequest();
const arr = [
{name: "test1", att: 100, def: 100},
{name: "test2", att: 100, def: 100},
{name: "test3", att: 100, def: 100},
{name: "test4", att: 100, def: 100},
]
arr.forEach((d) => {
batch.add(this.contract.methods.createCountry(d.name, d.att, d.def, 10, this.account).send.request(this.contractObject, (err, res) => {
if (err) {
throw err;
} else {
console.log(res);
}
}));
});
console.log(batch);
batch.execute();
我知道问题不是智能合约,因为我在 Remix 中对它进行了彻底的测试,并在不同的国家/地区进行了推送。我使用 web3 和 Metamask。
合约中的所有值都设置为“test4”
【问题讨论】:
-
这实际上是您正在运行的代码吗?您的帖子标题提到了
i,这听起来像是您在使用for循环,其中循环变量范围可能会导致您所描述的挑战。 -
我完全明白你的意思,很抱歉造成混乱。我曾经运行一个 for 循环,现在不再运行,实际上我找到了一个解决问题的解决方案,现在我将其作为答案发布。
标签: ethereum web3 web3js metamask