0
votes

I have this code that allows me to make a purchase of tokens with web3, apparently if the transaction is validated but when I click confirm, the following error appears:

inpage.js:1 MetaMask - RPC Error: Error: [ethjs-rpc] rpc error with payload {"id":5715960965839,"jsonrpc":"2.0","params":["0xf8ac178504a817c8008301022794cfeb869f69431e42cdb54a4f4f105c19c080a60180b844095ea7b3000000000000000000000000c89ce4735882c9f0f0fe26686c53074e09b0d55000000000000000000000000000000000000000000000000000000000000f4240820557a07ff18aba5ab0a8080f4a4b29e8736c4ded84e09cec8f66eba186995a6b22261fa041fd2e3351985a3b0a4e1ec9ef1be79c3513170810569b78ba9f238d36e781fa"],"method":"eth_sendRawTransaction"} [object Object]

try to uninstall the extension and reinstall it as mentioned in other places, but without getting any results

this is my code

/* 'metamask': */
const web3 = new Web3(window["ethereum"]);

const USDT_ADDRESS = "XxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const ORION_SALE_ADDRESS = "XxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
const usdtContract = new web3.eth.Contract(IRC20_JSON.abi, USDT_ADDRESS);

const saleContract = new web3.eth.Contract(
  ORION_SALE_JSON.abi,
  ORION_SALE_ADDRESS
);
let userWallet;

const getAddress = async () => {
  try {
    const accounts = await window.ethereum.enable();
    userWallet = accounts[0];
    
    console.log(accounts, ORION_SALE_JSON);
    if (!userWallet) {
      document.getElementById("msg").innerHTML =
        "Oops, we can't seem to find the address of your wallet. Please, log in into your metamask account using the chrome extension and then refresh the page";
    } else {
      document.getElementById("msg").innerHTML =
        "Your wallet have been successfully added";
    }
  } catch (error) {
    console.log(error);
  }
};

getAddress();
//buyTokenFunction
const myfunction = async () => {
  let inputVal = document.getElementById("myInput").value;
  if (inputVal !== "") {
    usdtContract.methods
      .approve(ORION_SALE_ADDRESS, (inputVal * 1e6).toFixed(0))
      .send({ from: userWallet })
      .once("transactionHash", (hash) => {
        saleContract.methods
          .buyTokens(userWallet, USDT_ADDRESS, (inputVal * 1e6).toFixed(0))
          .send({ from: userWallet, gas: 10000000 }, (_) => {
            // Waiting for the transaction to be mined
          })
          .then((_) => {
            // Success
          });
      });
  }
};
1

1 Answers

0
votes
  1. Trace inputVal (or output to the console). Or even better is the whole expression:
(inputVal * 1e6).toFixed(0)
  1. Determine in which method the error occurs: approve or buyToken.