0

I have a contract object. on top of it I am calling store() function.

const transactionResponse = contract.store("4");

const txReceipt = transactionResponse.wait(1);

Getting Below Error:

TypeError: transactionResponse.wait is not a function

2 Answers 2

3

Looks like control has jumped to line transactionResponse.wait(1) without waiting for a response from contract.store("4");.

Use the await keywork and it will work.

const transactionResponse = **await** contract.store("4");

const txReceipt = transactionResponse.wait(1);
0

Calling a method on a contract returns a promise as does the wait method. In your example above you are not waiting for the promise to resolve. There are a couple of ways you can do this. One of them is to use the async/await syntax.

async function handleStore() {
  const transactionResponse = await contract.store('4')
  const transactionReceipt = await transactionResponse.wait()
  return transactionReceipt
}

Notice here how the wait function isn't taking any arguments either.

Most all (if not all) methods you call on a contract will return a promise that you'll need to wait for. protip: If you use vscode, you can hover your mouse over the method and see its return value. When you see the keyword, "promise" you'll know for sure you need to await or promise chain.

The other way is to use the old-school promise chain method. Async/Await is really just a fancy, easier to read way of doing a promise chain. Like so

contract.store(4).then(transactionResponse => {
  transactionResponse.wait().then(receipt => {
    // do something with the receipt here.
  })
})

Again, notice that wait() takes no arguments.

I should mention this too, not all contract methods are transactions! Be careful not to try to wait() on a method that isn't a tx. I hope this helps

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.