Error: No "from" address specified in neither the given options, nor the default options. At Object.ContractNoFromAddressDefinedError

Viewed 52

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?

0 Answers
Related