0
    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”

4

2 回答 2

1

当背靠背发送许多事务时,您必须为每个事务设置随机数,并增加它。通常,nonce 是由节点为您设置的,但它不适用于多个顺序事务。

仅实际发送最后一笔交易的原因是, nonce可以用作在交易被挖掘之前覆盖交易的一种方式(例如,如果您发送的 gas 太少)。

我之前已经用代码示例回答了这个问题

重复事务挂起 - web3js,本地 geth

于 2018-05-18T01:19:01.733 回答
0

我为这个问题找到了一个 hacky 解决方案,并在 web3 github 上创建了一个问题。

在此处查看我的问题和解决方案:https ://github.com/ethereum/web3.js/issues/1636

我找不到一个简洁的解决方案,但我确信一旦问题得到解决,就会提出解决方案。

于 2018-05-17T14:54:05.370 回答