ethers.js
ethers.js copied to clipboard
provider.ts:910 Uncaught (in promise) TypeError: receipt.confirmations is not a function from localhost network
Ethers Version
6
Search Terms
No response
Describe the Problem
provider.ts:910 Uncaught (in promise) TypeError: receipt.confirmations is not a function at ContractTransactionResponse.wait (provider.ts:910:32) at async ContractTransactionResponse.wait (wrappers.ts:63:25) at async Proxy.mint (mint.vue:78:1)
rpc url is localhost:8545
Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
No response
Environment (Other)
No response
I have the same issue
I manage to fix this by changing the way you send transactions. having issue with this:
const tx = await ERC20Contract.approve(...args)
await tx.wait();
changing the code to the following solved the issue:
const data = ERC20Contract.interface.encodeFunctionData('approve', [...args])
const tx = signer.SendTransaction({
to: token address,
data
})
tx.wait()
@ricmoo have there been any updates on this? These issues have started cropping up in a project for me as well, although I am not using localhost. Been testing on Base and Polygon testnets, and the issue is occurring on both with all write calls I make to my smart contract.
One variation of the code snippet I've been trying (which used to work prior to ethers v6):
await instance.create(metadata).then(async (tx: any) => await tx.wait(1));
Where instance
is a Contract with a Signer attached and create is the RPC function I'm trying to call. It seems as though the wait() is working because the error gets thrown as soon as I see the MetaMask confirmation dialog, which is a few seconds after placing the transaction.
The result:
Uncaught (in promise) TypeError: receipt.confirmations is not a function
at Web3Provider.txListener (provider.js:1086:1)
at eval (base-provider.js:1936:1)
I can't seem to get the above solution to work for my case and I cannot try/catch the wait call to hide the error. This is present on the latest ethers (v6.8.0) and on the version I had previously (v6.7.1).
Could you provide a code snippet that reproduces the issue, @jbettenc?
It looks like you are getting a listener for a tx hash being called without a proper TransactionReceipt instance...
Could you provide a code snippet that reproduces the issue, @jbettenc?
It looks like you are getting a listener for a tx hash being called without a proper TransactionReceipt instance...
@ricmoo Yes, of course. Been working in a NextJS app, so I created a garbage class that calls a sample contract. This contract is on Polygon Mumbai testnet. We have also found similar results on Base and Base testnet too. I have not yet tested this on other networks, but I am assuming the behavior will be similar.
Here is the file:
import { getProviderUrl } from "@/utils/misc";
import { useWeb3React } from "@web3-react/core";
import { Contract, ethers } from "ethers";
function GarbageCall() {
const { library } = useWeb3React();
const abi = [
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: "string",
name: "data",
type: "string"
}
],
name: "DidSetData",
type: "event"
},
{
inputs: [],
name: "data",
outputs: [
{
internalType: "string",
name: "",
type: "string"
}
],
stateMutability: "view",
type: "function"
},
{
inputs: [
{
internalType: "string",
name: "data_",
type: "string"
}
],
name: "setData",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
];
return (
<>
<button
onClick={async () => {
const provider = new ethers.JsonRpcProvider(await getProviderUrl(library));
const contract = new Contract("0x2906d67A0929e1E6C9102AA4d97e1f1F9B112153", abi, provider);
const instance = contract.connect(library.getSigner()) as Contract;
try {
await instance.setData("Data").then(async (tx: any) => await tx.wait(1).then(() => console.log("success")));
} catch (err: any) {
console.log("error", err);
}
}}
>
Call smart contract
</button>
</>
);
}
export default GarbageCall;
This results in:
Uncaught (in promise) TypeError: receipt.confirmations is not a function
at Web3Provider.txListener (provider.js:1086:1)
at eval (base-provider.js:1936:1)
Note that my try/catch block does not end up calling the catch code, but instead crashes outside of this scope altogether. It sounds like you know what to look for here more than I do, but do please let me know if I can be of any assistance or if you need any additional details from me :)
The issue is indeed that confirmations is part of the already resolved object that causes the error..
I put in a PR to fix here
https://github.com/ethers-io/ethers.js/pull/4467
I'm facing this same error in my implementation, had to rollback to v5 as the same implementation is working there.
@braianxde The linked PR contains the root of the problem, which is when passing a v5 instance into the v6 library. They are not interchangeable, and it seems Babel or other transpile, when dealing with both versions is likely using .call or .apply to pass in the wrong object to the a v6 instance’s this
.
Are you using a dependency that is using v5? Can you check your package-lock.json?
Yep that was the problem.
I'm using Dynamic Wallet (@dynamic-labs/sdk-react) and it uses the v5 in the dependencies:
So I had to change the way that I was setting up the provider in my React application. (https://docs.dynamic.xyz/quickstart#step-4-stick-with-viem-or-switch-to-ethers)
Btw I verified the dependency using the pnpm why ethers
command in case someone else has problems with it.
Thank you for the quick response! That saved me a lot of time!