0

As I said in my other question, I'm using web3.js to create a DAPP. The problem is that it takes a lot to receive the update after the "await" function. In the following code:

allowAddress = async() => {
let approvedAddress = this.state.approvedAddress;
let approvedValue = this.state.amountAllowed;
this.setState({infoMessage:'Waiting for transaction...'});
try{
let accounts = await web3.eth.getAccounts();
await ContractName.methods.approve(approvedAddress, approvedValue).send({
  from: accounts[0]
//   value: web3.utils.toWei('0', 'ether')
});
console.log("IT WORKED");
}
catch(err){
    this.setState({infoMessage:"something went wrong"});
}
}

console.log("IT WORKED");works only and only after a very long time. Now I can't even specify the value: web3.utils.toWei('0','ether'); because it stops working.

In the past the part after await would run at the same time as metamask. Is there anything I can do?

0

I advice you to use a callback, not await/async style. Send method should return a tx hash to you, not a result of the transaction.

0

It doesn't have to do with web3js but with how fast your transaction is mined, and that is tied to your gas price. The higher the gas price, the faster it will get mined.

  • No. It actually mines pretty fast and it shows in MetaMask that the transaction is confirmed. It just doesn't show in the browser except after a long time the metamask notification that the transaction has been mined lol – Sophie259 Apr 23 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.