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.

Using Ethers to Find ETH sent from a contract to the method caller.

See original GitHub issue

Hey there!

First of all, thank you so much for the time you put into this library. It’s without question my favorite to work with.

I’m having a hard time figuring out how to see when a contract method returns ether to the sender. For example in the transaction 0x57d0a98e69c19195e0283358240b888ea06be8f4473f73c770ab6126c8278e82 wETH is being ‘Unwrapped’ and the contract is sending ether to the caller. Nothing jumps out to me when inspecting the TransactionResponse and TransactionReceipt. I’ve been looking through the docs and other issues and I haven’t been able to find a solution.

Any insight would be greatly appreciated.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
zemsecommented, Aug 1, 2020

You cannot see that through ethers.js directly. When contract sends ether to some address it is an internal transaction, which uses CALL opcode. Internal transactions aren’t included in receipts. To get ETH transfers you need to replay the transaction in EVM and check all CALL opcode uses in the stack, and from that just filter out those CALL uses with positive value.

But this process is non-trivial since different backends have different RPC APIs for the same thing. For example, in OpenEthereum it’s trace_replayTransaction and geth it’s debug_tracetransaction. Only name isn’t different but the responses are also different.

Last month, while writing test cases I wrote some code to see contract ETH transfers in ganache, the repo is public you can see it here if you are interested. I’m not sure if ganache’s response is same like geth, if it is then that code might work with geth too (I haven’t tried that in geth).

Also, Infura doesn’t support tracing yet in their APIs. I posted a request in their forum for the same and they seem to be positive to add it.

1reaction
travisallen6commented, Aug 1, 2020

I definitely noticed that etherscan shows that ether was sent to the caller. I’m hoping there is a way to see that the contract method sent ether to the caller using the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contracts — ethers.js 4.0.0 documentation
A Non-Constant method requires a fee (in Ether) to be paid, but may perform any state-changing operation desired, log events, send ether and...
Read more >
How to call a contract function/method using ethersjs
In case of RPC provider like Alchemy: // Second parameter is chainId, 1 for Ethereum mainnet const provider = new ethers.providers.
Read more >
How to send ETH to a contract function with ethers.js?
You can call the contracts function and pass it an object containing a value key. contractInstance.testFunction(<any function args>, ...
Read more >
Sending Static Calls to a Smart Contract With Ethers.js
Sending Static Calls to a Smart Contract With Ethers.js ... But let's try to transfer it with the callStatic method to see the...
Read more >
How to use Ethers.js Ethereum Library - Moonbeam Docs
Call methods are the type of interaction that don't modify the contract's storage (change variables), meaning no transaction needs to be sent. They...
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