MetaMask / MetaMask/metamask-mobile

Possible solution for https://github.com/MetaMask/metamask-extension/issues/3475

Open
#6,953 3 comments 0 reactions 0 assignees View on GitHub
team-wallet-api-platform-deprecated
Dominant language
TypeScript
Stars
3k
Forks
1.7k
Avg merge
1d 14h
Merged PRs (30d)
669

Description

Hi, as many users have pointed out here: https://github.com/MetaMask/metamask-extension/issues/3475
There are many cases where the backend needs to know the tx id that the frontend has signed.
As the Metamask team has explained in Issue 3475, because of the nonce the MM doesn't want to do this.
I have an idea that can satisfy both the devs that were requesting this feature and Metamask.

In my case, I have an Android app that wants to sign a transaction via Metamask, and get hold of the transaction hash that was signed, and send it to the backend server.
In a happy scenario, users will click 'send token' in our app , and this will open Metamask.
Then the user will perform the sign there, and will come back to our app.
Then our app will send the tx hash to the backend server.
All is good.

However, since users very often do not do what is told, sometimes they will sign the tx in MM, and before coming back to our app, they might close our app which leads to the backend server not being able to retrieve the hash.

To prevent these kinds of behaviors and to be safe that the backend server 'always' knows whether the tx has been signed,
how about using some kind of request id that holds the hash within?

1. The backend server does : metamask.createRequest(...fills in the tx requirements...) This createRequest() will return some kind of request id: "76242b52-aac8-45a8-ba9c-3004351b92bf" The backend keeps this request id.
2. Frontend receives the tx that should be signed from the backend and does metamask.sendTransaction() to open MM and wait for the user to sign.
3. From now on, even if the user does not come back to our app, the backend server can ping Metamask to see if this request id has been taken care of. GET findRequestResult(76242b52-aac8-45a8-ba9c-3004351b92bf) will return the hash that is in the request id, and the server can check whether the hash has been committed in the blockchain.

This way, the backend can know almost real time whether the tx has been completed AND Metamask doesn't have to think about the nonce issue.
You guys already had some kind of request id
![image](https://github.com/MetaMask/metamask-mobile/assets/109018862/21d8fd0b-e976-4904-a859-006b83a98090)
so I was looking around if I could use this, but I don't think it is meant to work as I have written above.

The impact of this is pretty big, as many developers in https://github.com/MetaMask/metamask-extension/issues/3475
were giving +1s and there are asks of this in StackOverflow as well.

Without this, the only way for me to do this is to listen to all the various Events that are going on, which I don't really want to do.

Contributor guide

Open the contributing guide

Research direction

Start with linked issue #3475 and the existing request-id behavior referenced in the mobile app; trace how sendTransaction reports completion today. Define whether a request ID can safely expose a signed transaction hash without conflicting with nonce handling, and verify that the backend can query the result when the app is closed.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
api, blockchain, mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.