0

I want to make a javascript code that does a metamask transaction and redirects the user to another page after the transation is completed. How easy this may sound, I can not figure it out. My current code lets the user complete the transaction, but it does not redirect the user to another page. Instead, it gives this error: "MetaMask - RPC Error: invalid argument 0: json: cannot unmarshal non-string into Go value of type common.Hash" I have looked it up, but I could not find any possible fix for my problem. This is my code:

    try {
  // send the transaction
  ethereum.send({
    method: 'eth_sendTransaction',
    params: [
      {
        to: contractAddress,
        from: userAddress,
        value: amt
      },
    ],
  }, (error, transactionHash) => {
    if (error) {
      console.error(error);
    } else {
      // check the status of the transaction using the transaction hash
      ethereum.request({
        method: 'eth_getTransactionReceipt',
        params: [transactionHash],
      }).then((receipt) => {
        // check if the transaction was successful
        if (receipt.status === '0x1') {
          console.log(`Transaction was successful`);
          // redirect to another page
          window.location.href = "page.php";
        } else {
          console.log(`Transaction failed`);
        }
      }).catch((error) => {
// This is the line of code the error is assigned to:
        console.error(error); 
      });
    }
  });
} catch (error) {
  console.error(error);
}
});

} else {
  document.getElementById("bericht").innerHTML = "Install Metamask before you continue";
  return;
}

I have tried looking the error up on internet, but nothing significant showed up. Could anyone help? Thank you in advance!

BlockB
  • 1

0 Answers0