-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get transaction hash immediately for transaction call? #511
Comments
Please see this solution, that should handle everything you need. :) In v5, the UncheckedJsonRpcProvider is built-in, and can either be accessed directly from the The returned TransactionResponses will not have any data populated, but the I'm also talking to several people regarding eth2.0 to solve this problem at the core, which is the signed transaction should be returned, not the transaction hash. It is east to compute the transaction hash from a signed transaction, it is impossible to compute the transaction from a transaction hash. Both are available, the API service call just drops it before returning it, which I think was to match the Bitcoin API more closely. Let me know if this helps. :) |
yes! thank you. |
Unfortunately, that solution does not quite provide parity. I built our tests using nock, to verify that the HTTP requests sent to the server match, and after making this change, they hang infinitely. May need some help later. |
@ricmoo Is there a solution for if you are using a |
You can subclass Wallet. What functionality are you trying to add? |
To get the hash immediately after calling a contract transaction.
…On Fri., May 10, 2019, 10:39 p.m. Richard Moore, ***@***.***> wrote:
You can subclass Wallet. What functionality are you trying to add?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#511 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUHUC65STJFUC3YOPYZWG3PUYWVZANCNFSM4HMEMKLA>
.
|
Just like how you subclassed JsonRpcSigner to do the same
On Fri., May 10, 2019, 11:29 p.m. Julian Wilson, <julianwlsn@gmail.com>
wrote:
… To get the hash immediately after calling a contract transaction.
On Fri., May 10, 2019, 10:39 p.m. Richard Moore, ***@***.***>
wrote:
> You can subclass Wallet. What functionality are you trying to add?
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <#511 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAUHUC65STJFUC3YOPYZWG3PUYWVZANCNFSM4HMEMKLA>
> .
>
|
Oh, a Wallet will always return immediately after sending, since it knows what was signed. This is only a problem for JSON-RPC. The LedgerSigner, Wallet, and any other Signer just work. The problem is the JSON-RPC API, which other methods of sending transactions do not need to deal with. :) |
@cellog Weird... Sounds like an event handler is still pending. Keep in mind the ethers does not |
Sorry for the delay - I ended up getting it sorted using this source: https://github.com/unlock-protocol/unlock/blob/master/unlock-js/src/FastJsonRpcSigner.js which provides 1-to-1 parity with the old way, just adds an intermediary |
One of the issues with your FastJsonRpcSigner is the reason we have to be sucky at JSON-RPC signing in the first place, many things may not be specified. For example, a user could use: signer.sendTransaction({
to: address,
value: parseEther("1.0")
}); Notice that gasPrice, nonce, et al. are not specified. Those are populated by the node, so in your code You can check out the UncheckedJsonRpcSigner in v5 for, and note that even though the values are unpopulated, the |
Thanks for checking into this. Since our use case is so narrow (only sending specific transactions to 1 smart contract), we won't run into that issue. I'm working up against a deadline for a project, so I won't take a look at v5 until after next week, but I'm looking forward |
Cool cool. I think this issue is taken care of now? If not, please feel free to re-open. Thanks! :) |
I'm using
... then the result won't be the txHash that I need to prompt the user with the respective etherscan link, but the full transaction object after being mined. Hence it does what I thought Is there a way to actually receive the txHash when the user actually sends the tx? Thanks! |
Hi @hilmarx , I have the same issue ! Did you manage to find a solution ? It's the kind of pb that makes us waste time for nothing although it should be considered as one of the main features and explained properly but I can't find any information about this. Best regards |
The tx object returned should have a This was addressed by MetaMask though, so recent versions should not suffer this problem anymore. |
See this for the UncheckedSigner for v4. |
Hi @ricmoo thank you for reply. Yes the response contains the transaction hash, but the issue is from a UI point of view. As developpers we need to let user know that its transaction is being processed and pending. The pb is that the response only comes after transaction has been mined, thus we can't show a loader to let user wait for the transaction because we don't know if the transaction is being processed we just get the result of mined transaction. What we need is to get transaction hash immediatly after user confirmed transaction on metamask. And after we check for transaction status trough liseners, but the current way makes listeners useless because response comes back too late once everything has been done. Best regards |
@kevin-wad exactly what the UncheckedSigner does; returns at tx with the hash immediately and leaves the rest of the TX empty (still with a wait). This is also fixed in the most recent MetaMask, it will now return the entire TX immediately, so the UncheckedSigner will become increasingly useless as more people upgrade. Sorry, I don’t know what pb stands for... :s |
Ok thank you very much @ricmoo ! pb means problem. Best regards |
Hi @ricmoo apparently the issue is still present on Metamask, I updated to 7.5.3 which is the current last version, but I still get this issue. Maybe I need to delete and re download ? But I think the issue is not gone |
Let me double check with MM that they’ve merged the change into the version they published on the Chrome Store then. The latest version on GitHub should work, but that is not very useful for most humans. :) |
Hi @ricmoo, did you find what is going on ? Best regards |
So @ricmoo, do you have any update on this issue what is going on ? Thanks again and Best regards |
@ricmoo It seems like this is still a problem. @kevin-wad Can you confirm? I am on MetaMask 7.7.8. |
i solved it by replacing the signer object with signer.connectUnchecked()
console.log("Transaction is confirmed"); |
@tomarsachin2271 , it works fine for the smart contract function which doesn't return any value from it. what about the smart contract function which return value. i need both return value and Txn. how can I do that? |
@iamRishvanth The return value of a transaction is not generally available. You must pay for every byte permanently stored on the blockchain, and since there is no additional cost to return a value, it isn’t stored. This is why cases where return values are required, you would generally use an event, which you do pay an additional 375 gas for (and additional beyond that each additional log entry, data, etc.). If you have access to an archive node or a node with debug or trace APIs available, you can use those API to replay the tx at the blockchain state, which will give you the return value. You can use the Make sense? |
Thank you again for ethers. Recently migrated all of our stuff from web3 to ethers, and it's been great.
There is one subtle but important difference between the two, however. When one calls
web3.eth.sendTransaction
, the promiEvent emits atransactionHash
event as soon as it knows what the hash will be.Ethers, on the other hand, does not return anything at the moment it receives the transaction hash, but instead polls
getTransaction
until we get our first mined block. Our UI is designed to show a"pending"
state in between the submission of the transaction and either its first mined block or its failure.Thus, instead we have a multi-second delay where nothing is shown except the modal we display to ask the user to confirm the transaction.
So, my question is whether there is a built-in way to get a poke of some kind when the transaction hash is available? If not, I suppose I could take the custom provider I made for using
fetch
instead offetchJson
and extend it to return a custom signer that returns a different form.However, this is a significant UX problem, I suspect I will not be the first trying to migrate over from web3 to mention this.
Could we discuss the flow of what is returned? For example, our app does the following:
With web3, we had to implement our own polling. Ethers actually has polling built in (nice) but there are just a couple of places we need information that ethers does not yet provide.
The other aspect of how we do this that is a bit unusual is that we use completely separate providers for our transaction sending, and for our transaction polling.
In any case, would love your advice on how to do this without changing ethers (if possible), and your thoughts about these use cases.
The text was updated successfully, but these errors were encountered: