簡體   English   中英

Metamask 返回 RPC 錯誤:錯誤:[ethjs-rpc] rpc 錯誤,有效載荷 {“id”:5715960965837,“jsonrpc”:“2.0”,“params”:

[英]Metamask returns RPC Error: Error: [ethjs-rpc] rpc error with payload {“id”:5715960965837,“jsonrpc”:“2.0”,“params”:

我有這段代碼允許我使用 web3 購買令牌,顯然如果交易得到驗證,但當我單擊確認時,會出現以下錯誤:

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

嘗試卸載擴展程序並按照其他地方所述重新安裝它,但沒有得到任何結果

這是我的代碼

/* '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. 跟蹤inputVal (或 output 到控制台)。 甚至更好的是整個表達式:
(inputVal * 1e6).toFixed(0)
  1. 確定錯誤發生在哪種方法中: approvebuyToken

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM