I am using two contracts. Contract-B has a function to receive 100 Dai tokens from users, but for that it needs to have increaseAllowance() of the Dai contract(contract-A) of that Dai Token.

I then make the following function in reactjs using ethers. What it does, is that, it gets abi from both contracts in the first two lines, then it calls the increaseAllowance() function using await and once it'll get the allowance then it should go to the next line and call the function of sendApplication(). So in simple, it should first call increaseAllowance() and then the sendApplication() on the blockchain. As it would increase allowance and the send application function would work after it, but what it does is that it calls both the function simultaneously and as there is no allowance yet so the sendApplication function fails and gives error of allowance, so i want it to be queued in line on the blockchain and shud run after the call of increaseAllowance() function

const sendApplication = async () => {
try {
      if(!ethereum) return alert("Please install MetaMask.");

      const contractDai = await getDAIContract(); //Dai Contract abi
      const contract = await getEtherContract(); //2nd Contract abi
      const increaseAllowance = await contractDai.increaseAllowance('2nd_contract_address', 100);
      const sendApplication = await contract.sendApplication(100);

        } catch (error) {
            console.log("error : ", error);

1 Answer 1


Both increaseAllowance and sendApplication modify states, so it will make transaction to ethereum. u need to wait for the transaction to mined.

const increaseAllowanceTx = await contractDai.increaseAllowance('2nd_contract_address', 100);
await increaseAllowanceTx.wait();

const sendApplicationTx = await contract.sendApplication(100);
await sendApplicationTx.wait();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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