I am integrating the MetaMask Unity Plugin given here: https://assetstore.unity.com/packages/decentralization/infrastructure/metamask-246786
and followed the docs provided here: https://c0f4f41c-2f55-4863-921b-sdk-docs.github.io/guide/metamask-sdk-unity.html
to allow users to connect their MetaMask mobile wallet app with my Windows Unity app, and for authorizing transactions.
I used their provided snippet for testing transactions on the Sepolia testnet (rpc: rpc.sepolia.org, chainID: 11155111):
var wallet = MetaMaskUnity.Instance.Wallet;
var transactionParams = new MetaMaskTranscation
{
To = "0xd00..................................a",
From = MetaMaskUnity.Instance.Wallet.SelectedAddress,
Value = "0x0" //------------------------> note
};
var request = new MetaMaskEthereumRequest
{
Method = "eth_sendTransaction",
Parameters = new MetaMaskTranscation[] { transactionParams }
};
await wallet.Request(request);
I modified the receiving address and the value to be sent. The wallet is connected and transactions are working, except for the incorrect amount shown and transferred to the receiver. I understand that the value requested from the plugin is in wei, whereas that shown in the mobile app will show ether amounts greater than 0.00001 eth. For the smaller amounts, I needed to confirm from the block explorer.
Here is an example transaction I did (DO NOT SCAN THIS):
For the following txRequests the Mobile Wallet shows corresponding amounts in the popup request.
Sent Request Received Request Gas Fee Total
1000000000000 0.00028 + 0.000032 = 0.000313
10000000000000 0.00045 + 0.000032 = 0.004536
100000000000000 0.07206 + 0.000032 = 0.007209
I do not understand this conversion, since as I understood once, 1 wei = 10^-18