question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Contract that uses InfuraProvider sends a transaction instead of calling the view contract function

See original GitHub issue

As stated, deploy a contract with a view function. Get the provider like

const provider = new ethers.providers.InfuraProvider('rinkeby', PROJECT_ID);
const contract = new ethers.Contract(CONTRACT_ADDRESS, ABI, provider); 

await contract.getListOfThingsForExample();

Then it throws this error

{
  ...
  reason: 'sending a transaction require a signer',
  code: 'UNSUPPORTED_OPERATION',
  operation: 'sendTransaction' 
}

Since this is a query, it shouldn’t require a signer. Which means contract is trying to send a transaction

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
psyudcommented, Mar 17, 2021

Seems like I was using v4.0 beta. Installed 5.0.32 and it’s working now. Thanks!

1reaction
ricmoocommented, Mar 17, 2021

Can you make sure your ABI correctly specifies that getListOfThingsExample is correctly marked as view or peer?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I send contract transactions? · Issue #461 · ethers-io ...
I want to send a contract transaction through infura provider, but I need a signer to do so. The problem is that the...
Read more >
What is the difference between a transaction and a call?
A call is a local invocation of a contract function that does not broadcast or publish anything on the blockchain. It is a...
Read more >
Ethereum JavaScript Libraries: web3.js vs. ethers.js (Part II)
We will be using Infura to deploy our contract to the testnet so we can ... view the UINT, which is done by...
Read more >
Providers — ethers.js 4.0.0 documentation
A Provider abstracts a connection to the Ethereum blockchain, for issuing queries and sending signed state changing transactions. The EtherscanProvider and ...
Read more >
Documentation - Ethers.js
The Contract object makes it easier to use an on-chain Contract as a normal ... "function balanceOf(address) view returns (uint)", // Send some...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found