Solidity
我如何在另一個方法結果中呼叫一個方法?
我想呼叫兩個方法,首先呼叫一個方法,然後在第一個方法成功後呼叫第二個方法下面是我的程式碼,請檢查並告訴我如何實現這一點
this.state.token.methods.approve(this.state.neutralG.address, qty).send({ from: this.state.account}). then('receipt', (receipt)=>{ this.state.neutralG.methods.createEscrow(intvalue, 3600, price, this.symbol, beneficiaryAddress, qty, this.tokenAddress).send({ from: this.state.account}). once('receipt', (receipt)=>{ this.setState({loading: false}) }) })
這不是呼叫第二筆交易。
你的,一次又一次是錯誤的。請嘗試如下:
this.state.token.methods.approve(this.state.neutralG.address, qty).send({ from: this.state.account}) .on('receipt', (receipt)=>{ this.callCreateEscrow(); console.log('receipt'); }) function callCreateEscrow(){ this.state.neutralG.methods.createEscrow(intvalue, 3600, price, this.symbol, beneficiaryAddress, qty, this.tokenAddress).send({ from: this.state.account}) .on('receipt', (receipt)=>{ this.setState({loading: false}) }) }
還請檢查 .on(’<>’, )…. 中的其他內容。它們可以是 ‘receipt’、‘confirmation’、’transactionHash’ 等,
參考:https ://web3js.readthedocs.io/en/v1.2.0/web3-eth-contract.html#id22