错误:“否”在给定选项和默认选项中都指定的地址。在object.contractnofromaddressdressdressError上

发布于 2025-02-09 21:00:44 字数 4074 浏览 1 评论 0原文

当我尝试接受NFT创建的其他帐户的出价时,我的代码正在较早工作,但是现在它说了这个错误。我尝试使用等待Web33.CurrentProvider,但没有解决。

我的接受代码在这里:

async function bidAccept() {
    var web3 = new Web3(window.ethereum);
    var tyye = "";
    if (tokendet.type === "erc721") {
      tyye = 721;
    } else {
      tyye = 1155;
    }
    try {
      setacceptbitstatus(true);
      var passAmt = parseFloat(YouWillPayFee) + parseFloat(YouWillGet);
      passAmt = passAmt.toFixed(config.toFixed);
      if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
        await window.web3.currentProvider.enable();
        web3 = new Web3(window.web3.currentProvider);  
      }
      var CoursetroContract = new web3.eth.Contract(DETH, dethContractAddr);
      var tokenBal = await CoursetroContract.methods
        .balanceOf(acceptbidaddress)
        .call();

      passAmt = web3.utils.toWei(passAmt).toString();

      var payAmt = parseFloat(passAmt);
      if (tokenBal >= payAmt) {
        if (tokendet.type === "erc721") {
          CoursetroContract = new web3.eth.Contract(BEP721, singleContract);
          var result = await CoursetroContract.methods
            .acceptBId(
              bidCurrency,
              acceptbidaddress,
              passAmt,
              productdet.tokenCounts
            )
            .send({ from: useraddress });
        } else {
          CoursetroContract = new web3.eth.Contract(BEP1155, multicontractAddr);
          var result = await CoursetroContract.methods
            .acceptBId(
              bidCurrency,
              acceptbidaddress,
              passAmt,
              productdet.tokenCounts,
              qtyVal
            )
            .send({ from: useraddress });
        }
        setacceptbitstatus(false);

        var adr = acceptbidaddress;
        var postdata = {
          tokenCounts: productdet.tokenCounts,
          tokenQuan: acceptcount,
          tokenOwner: productdet.tokenOwner,
          newTokenOwner: adr,
          type: tokendet.type,
        };
        if (tokendet.type === "erc721") {
          postdata = {
            tokenCounts: productdet.tokenCounts,
            tokenQuan: acceptcount,
            oldOwner: productdet.tokenOwner,
            newTokenOwner: acceptbidaddress,
            type: tokendet.type,
            acceptbidId: acceptbidId,
            contractAddress: singleContract,
            acceptbid: "yes",
            tokenPrice: totalpay,
            servicefee: servicePer,
          };
          var updated = await postMethod(
            baseurl + "api/singletoken-bit-buy",
            postdata
          );
          toastAlert("success", "Bid Accepted Successfully", "success");
          setTimeout(() => {
            window.location.href = "/Author?user=" + useraddress;
          }, 1500);
        } else if (tokendet.type === "erc1155") {
          postdata = {
            tokenCounts: productdet.tokenCounts,
            tokenQuan: acceptcount,
            oldOwner: productdet.tokenOwner,
            newTokenOwner: acceptbidaddress,
            type: tokendet.type,
            acceptbidId: acceptbidId,
            contractAddress: multicontractAddr,
            acceptbid: "yes",
            tokenPrice: totalpay,
            servicefee: servicePer,
          };
          var updated = await postMethod(
            baseurl + "api/multitoken-bit-buy",
            postdata
          );
          toastAlert("success", "Bid Accepted Successfully", "success");
          setTimeout(() => {
            window.location.href = "/Author?user=" + useraddress;
          }, 1500);
        }
      } else {
        setacceptbitstatus(false);
        toastAlert("error", "Bidder doesnt have Enough Balance ", "success");
      }
    } catch (err) {
      console.log(err);
      setacceptbitstatus(false);
      toastAlert("error", "Failed to accept", "success");
    }
  }

必须使用.enable()方法是某种内容,但不确定我如何错误或位置出错!还要注意一次,如果我重新打开页面时,就会发生一次,如果我对代码进行任何更改并保存任何更改并保存再一次,不重新加载代码将顺利运行,我获得了MetAmask通知以接受投标。

因此,我假设是否有一些价值在等待接受?

my code was working earlier when I try to accept the Bid from other accounts for NFT's created , but now it says this error. I tried using await for web3.currentProvider but it's not working out.

my code for accept bid is here:

async function bidAccept() {
    var web3 = new Web3(window.ethereum);
    var tyye = "";
    if (tokendet.type === "erc721") {
      tyye = 721;
    } else {
      tyye = 1155;
    }
    try {
      setacceptbitstatus(true);
      var passAmt = parseFloat(YouWillPayFee) + parseFloat(YouWillGet);
      passAmt = passAmt.toFixed(config.toFixed);
      if (typeof window !== 'undefined' && typeof window.web3 !== 'undefined') {
        await window.web3.currentProvider.enable();
        web3 = new Web3(window.web3.currentProvider);  
      }
      var CoursetroContract = new web3.eth.Contract(DETH, dethContractAddr);
      var tokenBal = await CoursetroContract.methods
        .balanceOf(acceptbidaddress)
        .call();

      passAmt = web3.utils.toWei(passAmt).toString();

      var payAmt = parseFloat(passAmt);
      if (tokenBal >= payAmt) {
        if (tokendet.type === "erc721") {
          CoursetroContract = new web3.eth.Contract(BEP721, singleContract);
          var result = await CoursetroContract.methods
            .acceptBId(
              bidCurrency,
              acceptbidaddress,
              passAmt,
              productdet.tokenCounts
            )
            .send({ from: useraddress });
        } else {
          CoursetroContract = new web3.eth.Contract(BEP1155, multicontractAddr);
          var result = await CoursetroContract.methods
            .acceptBId(
              bidCurrency,
              acceptbidaddress,
              passAmt,
              productdet.tokenCounts,
              qtyVal
            )
            .send({ from: useraddress });
        }
        setacceptbitstatus(false);

        var adr = acceptbidaddress;
        var postdata = {
          tokenCounts: productdet.tokenCounts,
          tokenQuan: acceptcount,
          tokenOwner: productdet.tokenOwner,
          newTokenOwner: adr,
          type: tokendet.type,
        };
        if (tokendet.type === "erc721") {
          postdata = {
            tokenCounts: productdet.tokenCounts,
            tokenQuan: acceptcount,
            oldOwner: productdet.tokenOwner,
            newTokenOwner: acceptbidaddress,
            type: tokendet.type,
            acceptbidId: acceptbidId,
            contractAddress: singleContract,
            acceptbid: "yes",
            tokenPrice: totalpay,
            servicefee: servicePer,
          };
          var updated = await postMethod(
            baseurl + "api/singletoken-bit-buy",
            postdata
          );
          toastAlert("success", "Bid Accepted Successfully", "success");
          setTimeout(() => {
            window.location.href = "/Author?user=" + useraddress;
          }, 1500);
        } else if (tokendet.type === "erc1155") {
          postdata = {
            tokenCounts: productdet.tokenCounts,
            tokenQuan: acceptcount,
            oldOwner: productdet.tokenOwner,
            newTokenOwner: acceptbidaddress,
            type: tokendet.type,
            acceptbidId: acceptbidId,
            contractAddress: multicontractAddr,
            acceptbid: "yes",
            tokenPrice: totalpay,
            servicefee: servicePer,
          };
          var updated = await postMethod(
            baseurl + "api/multitoken-bit-buy",
            postdata
          );
          toastAlert("success", "Bid Accepted Successfully", "success");
          setTimeout(() => {
            window.location.href = "/Author?user=" + useraddress;
          }, 1500);
        }
      } else {
        setacceptbitstatus(false);
        toastAlert("error", "Bidder doesnt have Enough Balance ", "success");
      }
    } catch (err) {
      console.log(err);
      setacceptbitstatus(false);
      toastAlert("error", "Failed to accept", "success");
    }
  }

must be something with .enable() method but not sure either how or where i am going wrong !Also a note this happens once when the page is reopened , if i do any changes in code and save it again , without reloading the code will run smoothly and I get the metamask notification to accept bid.

So i am assuming if some value is waiting to be accepted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文