Javascript Web3未按预期返回承诺
我试图调用一个web3函数,但它没有像预期的那样返回承诺。然而,这个陷阱似乎起到了很好的作用 合同要求:Javascript Web3未按预期返回承诺,javascript,solidity,web3,Javascript,Solidity,Web3,我试图调用一个web3函数,但它没有像预期的那样返回承诺。然而,这个陷阱似乎起到了很好的作用 合同要求: const requestDebenture = async (debentureAmount) => { createContractInstance(); await mGenerousInstance.methods.requestMDebenture(web3.utils.toWei(debentureAmount.toString(), "ether")).s
const requestDebenture = async (debentureAmount) => {
createContractInstance();
await mGenerousInstance.methods.requestMDebenture(web3.utils.toWei(debentureAmount.toString(), "ether")).send({from: account}, (_, txHash) => {
if(txHash) {
notify.hash(txHash);
}
}).then().catch();
}
尝试访问调用的函数:
requestDebenture = async (e) => {
const { debentureAmount } = this.state
this.setState({debentureError: "", isInDebenture: true});
await requestDebenture(debentureAmount)
.then(async () => {
await fetchAccountBalances().catch();
await fetchAccountValues().catch();
await fetchAccountValues().catch();
this.setState({isInDebenture: false, debentureShowing: false});
})
.catch(() => {
this.setState({isInDebenture: false, debentureError: "An error has occurred while requesting for your funds"});
});
}
谢谢。
requestDebenture
用作两个不同功能的名称…!?它们位于两个独立的文件中,几乎不重要。在第二个文件中,您定义了一个函数requestDebenture
,该函数尝试调用一个函数requestDebenture
。该名称在该文件中只能表示一种内容,而不能表示两种不同的内容。按原样,此函数似乎将自己称为…?!