Fabrizio Bertone
Fabrizio Bertone's Blog

Fabrizio Bertone's Blog

How to solve error: sending a transaction requires a signer (operation="sendtransaction", code=unsupported_operation, version=contracts/5.5.0)

In Ethers.js

Fabrizio Bertone's photo
Fabrizio Bertone
·Jan 17, 2022·

2 min read

This is quite a common issue for beginning Web 3 developers:

sending a transaction requires a signer (operation="sendtransaction", code=unsupported_operation, version=contracts/5.5.0)

When interacting with Smart Contracts on the Ethereum Blockchain, reading operations can be performed without using Gas for fees, for this reason you don't need to sign transactions.

On the other hand, when you want to call a Smart Contract method that requires changing the status of the Blockchain, for example to store or modify some data, you are generally required to pay fees in ETH to the network.

To pay fees you need to sign the transaction with the key of your connected wallet (e.g.: MetaMask).

Let's imagine that we created our provider this way:

provider = new ethers.providers.Web3Provider(window.ethereum)

And you instantiated you Smart Contract like this:

greeterContract = new ethers.Contract(greeterAddress, greeterAbi, provider)

It doesn't really matter how you instantiated the Provider and Contract as long as they are working, just pay attention to the names of the objects.

Now you can get the Signer with this line:

signer = provider.getSigner()

And you can connect the signer to the Contract this way:

greeterContractWithSigner = greeterContract.connect(signer)

To use the methods of the Smart Contract you can now use the in place of the greeterContract:

  () => {
  error => {
    console.log('Oh, no! We encountered an error: ', error)

Now it should work, let me know in the comments!

Share this