首页 > 解决方案 > Web3 批量请求返回未定义

问题描述

我正在尝试通过 BatchRequest 调用 BNT 和另一个 ERC20 的批准函数。

第一个请求效果很好,但第二个返回未定义,如果我交换订单也一样。

此外,如果我取消第一笔交易,第二笔交易也很好。

wrapperApprove = async () => {

// GET DATA
const web3 = this.props.MobXStorage.web3
let batch = new web3.BatchRequest()
const amount = await this.calculateConnectorBySmartTokenAmount()
const tokenInfo = this.getInfoBySymbol()
const converterAddress = tokenInfo[1]
const connectorAddress = tokenInfo[2]

const bnt = this.props.MobXStorage.web3.eth.Contract(ABISmartToken, 
BNTToken)
const connector = 
this.props.MobXStorage.web3.eth.Contract(ABISmartToken, 
connectorAddress)

// MAKE BATCH REQUEST
batch.add(connector.methods.approve(
converterAddress,
this.props.MobXStorage.web3.utils.toWei(String(amount[1]))
).send.request({from: this.props.MobXStorage.accounts[0]}))


batch.add(bnt.methods.approve(
converterAddress,
this.props.MobXStorage.web3.utils.toWei(String(amount[0]))
).send.request({from: this.props.MobXStorage.accounts[0]}))

batch.execute()
}

标签: web3js

解决方案


推荐阅读