ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.95k stars 1.84k forks source link

V6 - getTransactionCount is not a function of provider #4107

Open hanscj1 opened 1 year ago

hanscj1 commented 1 year ago

Ethers Version

6.4

Search Terms

sendTransaction

Describe the Problem

I have been using ethers for the last year and upgraded to 6.2 and no issues. I just upgraded to 6.4 and received the following error: TypeError: checkProvider(...).getTransactionCount is not a function at _Wallet.getNonce (hdwallet-8330977f.js:5442:55) at async _Wallet.populateTransaction (hdwallet-8330977f.js:5452:19) at async _Wallet.sendTransaction (hdwallet-8330977f.js:5534:17) at async processTransaction

Originally, I used signer.getNonce() for the nonce value, but I received the above error. I then removed the nonce value from the transaction and it still happened. I'm also using Infura. When I looked at the 6.4 code it is happening in the AbstractSigner class.

Whatever checkProvider(this, "getTransactionCount") is pulling back does not have .getTransactionCount defined.

Please advise. Thanks

Code Snippet

class AbstractSigner {
  constructor(provider) {
    __publicField(this, "provider");
    defineProperties(this, { provider: provider || null });
  }
  async getNonce(blockTag) {
    return checkProvider(this, "getTransactionCount").getTransactionCount(await this.getAddress(), blockTag);
  }
:
:
}

 Whatever checkProvider(this, "getTransactionCount") is pulling back does not have .getTransactionCount defined.

Contract ABI

No response

Errors

TypeError: checkProvider(...).getTransactionCount is not a function
    at _Wallet.getNonce (hdwallet-8330977f.js:5442:55)
    at async _Wallet.populateTransaction (hdwallet-8330977f.js:5452:19)
    at async _Wallet.sendTransaction (hdwallet-8330977f.js:5534:17)
    at async processTransaction

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli)

Environment (Other)

No response

hanscj1 commented 1 year ago

I went out to etherscan, got the last nonce used (using Goerli for testing), and put the next number (hard coded to test). I got further but then I received another error: TypeError: this.provider.getNetwork is not a function at _Wallet.populateTransaction (hdwallet-8330977f.js:5457:41) at async _Wallet.sendTransaction (hdwallet-8330977f.js:5534:17) at async HTMLButtonElement.handleApprove (button on form)

The code it points to is: async populateTransaction(tx) { const provider = checkProvider(this, "populateTransaction"); const pop = await populate(this, tx); if (pop.nonce == null) { pop.nonce = await this.getNonce("pending"); } if (pop.gasLimit == null) { pop.gasLimit = await this.estimateGas(pop); } const network = await this.provider.getNetwork(); : : }

It would appear that 'provider' is not being set correctly or I have something else going on.

ricmoo commented 1 year ago

What are you passing into the Signer during instantiation? Nothing in that area should have changed...

hanscj1 commented 1 year ago

const signer = new ethers.Wallet(trans.privateKey, provider); // Provider value passed validity test : address = await signer.getAddress(); // Passes with correct address nonce = await signer.getNonce(); // Fails with the above

When I inspect provider it shows the correct Infura projectId. When I look at signer it shows the correct privateKey, provider and address.

hanscj1 commented 1 year ago

Oh, thanks for the reply. I will continue looking at different things. I did create a new function in the same app but used the alchemy sdk (tried a different provider) which I believe uses ethers 5.7. It worked.