I am making Ecom mobile app in Ionic-angular with crypto payments using MetaMask option,
When i am sending the request using eth_requestAccounts its returns user publickey in web but retuning empty response in mobile app, what i was missed to get publickey from metamsk app to ecom mobile app.
Is there any other options to connect MetaMask app from my ecomapp and make transactions.
Kindly share.
Thank you
Hello @azarudeen, welcome to MetaMask community!
Feel free to check on MetaMask Docs and the Github repository for anything you may have missed.
I want to code or doc for a mobile app to mobile app communications,
Not browser to app or site communications
You have that in what i linked above too. Mobile integration.
Hello @azarudeen !
We need more information about your problem, perhaps pieces of your code. You can post it here or in an issue on github. By the way you used MetaMask deep link generator ?
const web3 = new Web3();
const MMSDK = new MetaMaskSDK();
console.log(MMSDK);
this.ethereum = MMSDK.getProvider();
console.log(this.ethereum);
// const accounts = await this.ethereum.getAccounts();
const accounts = await this.ethereum.request({
method: 'eth_requestAccounts',
}).then((result:any)=>{
console.log(result);
}).catch((error: any) => {
// If the request fails, the Promise will reject with an error.
console.log(error);
});
I want a public id as a response after the app connected
Hello, Iām having the same issue right now, Iām using ionic react trying to authenticate with MetaMask and here is what I know at the moment :
-The prompt on the MetaMask app does appear after the redirect and it sends me back to my app correctly
-Iāve tried using await ethereum.request({ method: 'eth_requestAccounts' })
and I never got to the next code line
-I then tried to use a ā.then().catchā and it doesnāt seems to reach the inside of the ā.then()ā, the ā.catch()ā does fire correctly showing āError: Channel already createdā if I try to reload which is normal. That version let me get to the next line since it doesnāt wait.
Iām using a emulator on android studio, I started with a pixel 2 API 28 (android 9) and now I use a pixel 4 API 33 (android 13).
Both emulator worked the same way except that a few times the prompt did not show on the pixel 2 and I got other problems while looking if walletconnect could be an easy alternative.
I did get an error 1013 at some point on the pixel 2 but I donāt think it helps.
Here is my code sample :
```
BackgroundMode.enable();
const MMSDK = new MetaMaskSDK({timer:BackgroundMode, //I am aware that BackgroundMode might not work the same way as react native but when I began testing I had to put something here for the prompt to show itsel
dappMetadata: {
injectProvider: false,
communicationLayerPreference: āwebrtcā, //injectprovider and communicationLayerPreference didnāt change anything when I added it
name: "myappā',
url: 'myappLink
}});
const ethereum = MMSDK.getProvider();
//let tmp = await ethereum.request({ method: 'eth_requestAccounts' });
ethereum.request({ method: 'eth_requestAccounts' }).then(r=>console.log("My address : "+r)).catch(e=>console.log(e))
//this.setState({value:tmp})
BackgroundMode.disable();```
Hi,
if you use await
then you canāt use the .then
as itās a promise structure and not an async/await one.
So you can:
window.ethereum
.request({
method: "eth_requestAccounts",
params: [],
})
.then((res) => console.log("request accounts", res))
.catch((e) => console.log("request accounts ERR", e));
or
const accounts = await window.ethereum
.request({
method: "eth_requestAccounts",
params: [],
});
console.log("request accounts", accounts);
make sure you are also sending the params
option
Hi, I do know the difference between as it should be seen in the code sample (the await method is commented out) even tho something went wrong with the formatting.
Iāve tried adding the params
option but it didnāt change anything.
When I see your example you donāt seem to use the MetaMask sdk and Iām pretty sure window.ethereum
will not work correctly in a mobile app (not mobile browser) where the issue is but if there is a way for it to work Iād be glad to know
new MetaMaskSDK
creates the window.ethereum
that you can then use and access.
Please use socket
as communicationLayerPreference
and let me know if this works for you.
Also I suggest you to join our Discord server (link on the SDK website) so that other users can help you with that.
I just swapped to communicationLayerPreference: 'socket'
and it seems better on web but it was already working and gave me the address I want.
On mobile (mobile app on emulator, I didnāt try inside a mobile browser) it doesnāt change anything, the code inside the .then()
never seem to run
ethereum.request({ method: 'eth_requestAccounts' }).then(r=>console.log("address : "+r)).catch(e=>console.log(e))
Iāll continue searching later on this week and Iāll look after the discord at that point.
Iāll also see if the appstatechange event gives me anything when I get back to my app after the MetaMask prompt and maybe itāll help finding the problem.
@Intern are you got a solution?
Hi @andreahaku
I was tried above your code but its not working same issue
Not retuning account/key
Hello, I donāt have a solution yet. I tried many things and right now Iām just trying to get the react native example to work.
Iāve also tried to use walletconnect but the v2 isnāt supported yet and v1 is soon unsupported.
I have yet to see on discord as I have yet to take the opportunity to join.
I hope that if I get the example to work Iāll be able to find a solution for ionic but if not I guess Iāll have to swap framework (if react native work at some point) as I canāt really delay this project.
On another note, Iāve tried to follow the tutorial a bit further and use ether.js as proposed but there are polyfill problems that I could solve for web but couldnāt compile for mobile anymore.
Maybe the web3 library or another one may work but I have yet to try. So ionic might not be ready for that purpose (even tho I think I just didnāt find the way atm).
Hi @Intern
Hope this one will help to you
npm i @walletconnect/client
for more details visit npm page
Hello, I believe this is a deprecated package and as I said MetaMask doesnāt support the next version yet and that version is soon unusable.
I finally managed to get the account address using the same method as before but in react-native so I think Iāll stick with that.
I followed the tutorial here : https://c0f4f41c-2f55-4863-921b-sdk-docs.github.io/guide/metamask-sdk-js/metamask-sdk-react-native.html
and did a few tweaks to get it working. The example didnāt work for me but starting from scratch, removing the crypto package and adding
resolver: { extraNodeModules: { crypto:require.resolve('react-native-crypto'), }, },
to my metro.config.js did the tricks but I havenāt dealt with etherjs yet, I think Iāll try without as I donāt need much then Iāll see if it is needed and can works.
Hello. About walletconnect, these are the latest information and dates on it.
when i am calling await web3.eth.accounts.signTransaction(
transaction,
this.privateKey
);
method showing this error
any solutions
Hi @azarudeen and @Intern ,
Would you please open a ticket on āMetaMask-mobileā repo @
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.