MetaMask / metamask-sdk

The simplest yet most secure way to connect your blockchain-based applications to millions of MetaMask Wallet users.
https://metamask.io/sdk/
Other
171 stars 106 forks source link

[Bug]: Data don't work if I use transactionParameters #1014

Open filipe56 opened 2 weeks ago

filipe56 commented 2 weeks ago

SDK

React-Native

Provide environment information

I'm using react-native and testing on the iPhone. I'm having trouble getting the transfer result and the updated balance.

MetaMask SDK Version

0.28.2

MetaMask Mobile app Version

7.29.2

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Describe the Bug

There is a currency called RAI, however, when I use the function

web3 = new Web3(provider);
contract = new web3.eth.Contract(contractAbi, contractAddress);
contract.methods.transfer(recipient, amount).send({ from: account })

on the web it works, and if I use it for the MetaMask app, it opens the app and shows the name of the currency. But I don't get a response when I'm waiting for the transaction result. So for the app I tried to use the code below:

web3 = new Web3(provider);
contract = new web3.eth.Contract(contractAbi, contractAddress);
const transactionParameters = {
to,
from,
data: contract.methods.transfer(to, value).encodeABI(),
};
const txHash = await provider?.request({
method: 'eth_sendTransaction',
params: [transactionParameters],
});

The name of the currency does not appear in the MetaMask app, instead the name ERC20 appears.

I tried to use the same function as on the web, but I don't get any feedback when there is no error and I don't know how to get this feedback.

Expected Behavior

Get feedback from the Metamask app whether the transaction was successful or not. And the current balance value.

Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster

No response

To Reproduce

package.json:

"@metamask/sdk": "^0.28.2",
"@metamask/sdk-react": "^0.27.0",
"@react-native-async-storage/async-storage": "^2.0.0",
"ethers": "5.7.2",
"react": "^18.2.0",
"react-native": "0.72.7",

Use the function below:

const sendTransaction = async () => {
    const to = inputAdress;
    const value = (parseFloat(inputValue) * 10 ** 4);
    let from = account
    try {
    web3 = new Web3(provider);
    contract = new web3.eth.Contract(contractAbi, contractAddress);
    const transactionParameters = {
      to,
      from, 
      data: contract.methods.transfer(to, value).encodeABI(), 
    };

    const txHash = await provider?.request({
      method: 'eth_sendTransaction',
      params: [transactionParameters],
    });
    console.log("txHash",txHash);

    } catch (e) {
      Alert.alert('Erro na transferência');
      setLoading(false);
    }
  };
filipe56 commented 1 week ago

Which pull request has this fix? @summerly01