Using Ethers to Find ETH sent from a contract to the method caller.
See original GitHub issueHey 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:
- Created 3 years ago
- Comments:8
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 positivevalue
.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’sdebug_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.
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.