Check if transaction was sent with ethereum mainnet or ropsten and get receipt when etheruem arrives in account?

I have code for sending Ethereum with metamask

I am in the testing phase so i am using the ropsten test network to send Eth

the code below gives a receipt

       to: addr,
       value: ethers.utils.parseEther(stringEther)
     });
     
     console.log("tx: ", tx);
     setTxs([tx]);
 console.log("tx: ", tx) basically logs a receipt 

though from this how can I tell if the user has sent my wallet real ethereum and not the fake testing ethereum

so i can log it in my database, as I want to return from the function if the Ethereum was the fake etheruem , and only write to the database if it was real Ethereum

also how can a get an actual receipt in react js when the real ethereum is fully mined and in my account?

1 Like

Hey @benpalmer661, welcome to the MetaMask community! :fox_face:

Ethereum mainnet and Ropsten are both different networks, using different tokens. If the Ethereum was sent on Ropsten, then it is just test ETH. It was sent on Ethereum mainnet, then it is real ETH.

Smart contracts/dapps are deployed separately on Ethereum and on Ropsten, so the two networks do not share any data.

1 Like

Thanks, though my problem is differentiating the two in react js

as right now on my website someone could pay with Ropsten and it would update my database saying the have paid and I would send them a product even though they paid with Ropsten , so my question is: In React Js code how do I tell if someone has made a payment with Ropsten or Ethereum Mainnet ? so I am not sending someone who hasn’t paid Product unless they have paid with Ethereum Mainnet? and to further explain, I do not want to manually go and check if someone has paid myself ,

Is your React frontend talking to a smart contract on your backend? Are they paying through their MetaMask wallet?

If the smart contract is deployed on Ropsten, then only payments on Ropsten can be received. If the smart contract is deployed on Ethereum mainnet then only payments on Ethereum can be received.

Hopefully that helps :slight_smile:

2 Likes

My react front end is running the metamask code , and yes they are paying through their metamask wallet

Right now I am testing my app, I can change to ropsten on metamask , click purchase
and will my code it logs into the my database saying that I have paid? and once deployed I don’t see how this will change ?

is there any way with my code below to do something like;

let ethType = tx.EthType

if ( ethType === ropsten) {
alert("sorry please make paymet with Ethereum Mainnet not Ropsten)
return
}

my code is below,

const makePurchase = async () => {

try {
  if (!window.ethereum)
    throw new Error("No crypto wallet found. Please install it.");

  await window.ethereum.request({ method: 'eth_requestAccounts' });

  const provider = new ethers.providers.Web3Provider(window.ethereum);

  const signer = provider.getSigner();

var addr = “0x5E43C15D965a7a132401b9c1DCFd21a14037497D”

  ethers.utils.getAddress(addr);

  var stringEther = String(amountInEth)

  const tx = await signer.sendTransaction({
    to: addr,
    value: ethers.utils.parseEther(stringEther)
  });
  
  console.log("tx: ", tx);

// here we add the transaction to the database,

So i can’t just do something like if tx.network !== “mainnet”. {. deny transaction- no real funds paid? }. and i have to do some sort of api request to eth scan? is that correct ? and answer from a real programmer who uses react js would be nice

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.