I’m working with Hardhat to deploy smart contracts on the Polygon network. Everything seems to work fine most of the time, but I keep running into issues when I switch between different networks.
Here’s what happens: when I change from mainnet to testnet (specifically to rpc-mumbai.maticvigil.com), I start getting this error: ProviderError: invalid sender.
The weird part is that when I modify my hardhat.config.js file to use a different RPC endpoint like matic-mumbai.chainstacklabs.com, everything works perfectly again. I can deploy contracts and mint tokens without any problems.
Has anyone else experienced this kind of behavior with Polygon and Hardhat? Is this a common issue or am I missing something in my configuration?
i totally get what ur saying! polygon rpcs can be a mess sometimes. maticvigil is known to be iffy lol. ankr and alchemy are def better options for deployment. just remember to double-check what version of hardhat ur using too.
oh wow, this is actually pretty intresting! i’ve seen similar weirdness with polygon rpcs but never really dug into why certain endpoints throw that specific error.
are you using the same wallet/private key setup for both endpoints? like, does your hardhat config have the same accounts array configured for both networks? sometimes the “invalid sender” thing pops up when there’s a mismatch between what the rpc expects and what you’re sending.
also curious - does this happen immediately when you switch, or only after you’ve been using the maticvigil endpoint for a while? i’m wondering if it could be some kind of rate limiting or session timeout issue on their end.
have you tried clearing your hardhat cache between switches? sometimes npx hardhat clean helps with weird network switching issues.
what’s your experience been like with other polygon rpcs besides chainstacklabs? would love to know if this is just a maticvigil thing or if you’ve hit similar issues elsewhere!
This exact issue plagued me for weeks when I was setting up my Polygon deployment pipeline. The problem with maticvigil.com endpoints stems from their stricter validation of transaction parameters compared to other RPC providers. What fixed it for me was explicitly setting the gasPrice and gasLimit in my deployment scripts rather than letting Hardhat estimate them automatically. The maticvigil nodes seem to reject transactions when the gas estimation doesn’t align with their internal validation rules. I ended up switching to Polygon’s official RPC endpoints or QuickNode for production deployments since they handle gas estimation more reliably. You might also want to check if your nonce management is consistent between network switches - sometimes the cached nonce values get out of sync when jumping between different RPC providers.