Introduction
One of the most common and confusing issues you might fall into while working on testing solidity contracts using Ethere.js on Hardhat is:
Error: VoidSigner cannot sign transactions (operation=”signTransaction”, code=UNSUPPORTED_OPERATION, version=abstract-signer/5.7.0)
It means that the current transaction you are trying to execute cannot be signed, because the signer you provided is a VoidSigner.
A VoidSigner according to the Ethers.js documentation is:
a simple Signer which cannot sign.
Essentially it’s only valid for read-only operations. If the operation you’re trying to execute changes some data, then it will fail with the above error.
Example
Let’s say we have a contract called Foo.sol:
And the test for that contract looks like the following:
If we run this test we will get the following error:
Error: VoidSigner cannot sign transactions (operation=”signTransaction”, code=UNSUPPORTED_OPERATION, version=abstract-signer/5.7.0)
By default, when passing an address as a String, it's considered a VoidSigner, hence why we get the error.
The fix
Instead of passing a VoidSigner, we’ll need to pass a Signer instance.
Conclusion
I hope you find this article useful!
If you like short and simple articles filled with great tips and new tools consider subscribing to my newsletter.