[SOLVED] Metamask not coming up to sign Transaction

Hi,

I am having an issue when calling a function to interact with a contract and im quite stumped about what is going on. And any ideas would be greatly appreciated. Im able to login no problem to moralis.

errors.js:28 Uncaught (in promise) Error: Returned error: unknown account
    at Object.ErrorResponse (errors.js:28)
    at index.js:302
    at XMLHttpRequest.i.onreadystatechange (index.js:98)

This is in my index.html

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
    <script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>
    <script type="text/javascript"src="abi.js"></script>

This is in my main.js

     // connect to Moralis server
         Moralis.initialize("fQ5bhUdiCiWmI9OyDffHKypokEpG56V5z7cHGAYK");
         Moralis.serverURL = "https://oolhmy6ryxge.bigmoralis.com:2053/server";
   
   let contractAddress = "0x9645633E13579a9ed3F973b0C146551FEa8A92Ae"
   const NODE_URL = "https://speedy-nodes-nyc.moralis.io/91a948142eb4408b51cf3875/polygon/mumbai/archive"

And I have a button that calls a function.

async function upload(){
let contract = new web3.eth.Contract(contractAbi,contractAddress)
contract.methods.createNewSpecies(“svgsentfromBrowser”,3,“browserszs”,false).send({from: ethereum.selectedAddress, value:1000000000000000}).on(‘transactionHash’, function(hash){
}).on(‘receipt’, function(receipt){
console.log(receipt)
})

}

Thanks again!

What happens if you write something like:

receipt = await contract.methods.createNewSpecies(“svgsentfromBrowser”,3,“browserszs”,false).send({from: ethereum.selectedAddress, value:1000000000000000});
console.log(receipt)

I unfortunately still get the same error. I tried it on multiple browsers but still the same too.

errors.js:28 Uncaught (in promise) Error: Returned error: unknown account
    at Object.ErrorResponse (errors.js:28)
    at index.js:302
    at XMLHttpRequest.i.onreadystatechange (index.js:98)

Can you provide a minimal HTML + javascript + ABI that would generate that error?

Here is what I have. Let me know if you need anything else.

<!doctype html>

<html lang="en">

<head>

  <title>A Basic HTML5 Template</title>

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>

  <script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>

  

</head>

<body>

  

  <button id="btn-create">createNewSpecies</button>

  <button id="btn-login">Moralis Login</button>

  <button id="btn-logout">Logout</button>

 <script>

  Moralis.initialize("fQ5bhUdiCiWmI9OyDffHKypokEpG56V5z7cHGAYK");

  Moralis.serverURL = "https://oolhmy6ryxge.bigmoralis.com:2053/server";

let contractAddress = "0x9645633E13579a9ed3F973b0C146551FEa8A92Ae"

const NODE_URL = "https://speedy-nodes-nyc.moralis.io/91a948142eb4408b51cf3875/polygon/mumbai/archive"

let web3 = new Web3(new Web3.providers.HttpProvider(NODE_URL))

    

  let abiContract = [{

    "inputs": [

      {

        "internalType": "string",

        "name": "svgImage",

        "type": "string"

      },

      {

        "internalType": "uint256",

        "name": "numberToCreate",

        "type": "uint256"

      },

      {

        "internalType": "string",

        "name": "speciesName_sent",

        "type": "string"

      },

      {

        "internalType": "bool",

        "name": "wantsToKeepOne",

        "type": "bool"

      }

    ],

    "name": "createNewSpecies",

    "outputs": [],

    "stateMutability": "payable",

    "type": "function"

  }]

        

  async function upload(){

    let contract = new web3.eth.Contract(abiContract,contractAddress)

     receipt = await contract.methods.createNewSpecies('svgsentfromBrowser',3,'browserszs',false).send({from: ethereum.selectedAddress, value:1000000000000000})

    console.log(receipt)

    }

  async function login() {

    let user = Moralis.User.current();

    if (!user) {user = await Moralis.Web3.authenticate();}

    console.log("logged in user:", user);

  }

  async function logOut() {

    await Moralis.User.logOut();

    console.log("logged out");

  }

  document.getElementById("btn-login").onclick = login;

  document.getElementById("btn-logout").onclick = logOut;

  document.getElementById("btn-create").onclick = upload;

  </script>

</body>

</html>

Try this:

<!doctype html>
<html lang="en">
<head>

  <title>A Basic HTML5 Template</title>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/moralis.js"></script>
</head>
<body>

  <button id="btn-create">createNewSpecies</button>
  <button id="btn-login">Moralis Login</button>
  <button id="btn-logout">Logout</button>

 <script>

  Moralis.initialize("fQ5bhUdiCiWmI9OyDffHKypokEpG56V5z7cHGAYK");
  Moralis.serverURL = "https://oolhmy6ryxge.bigmoralis.com:2053/server";

let contractAddress = "0x9645633E13579a9ed3F973b0C146551FEa8A92Ae"


  let abiContract = [{

    "inputs": [

      {

        "internalType": "string",

        "name": "svgImage",

        "type": "string"

      },

      {

        "internalType": "uint256",

        "name": "numberToCreate",

        "type": "uint256"

      },

      {

        "internalType": "string",

        "name": "speciesName_sent",

        "type": "string"

      },

      {

        "internalType": "bool",

        "name": "wantsToKeepOne",

        "type": "bool"

      }

    ],

    "name": "createNewSpecies",

    "outputs": [],

    "stateMutability": "payable",

    "type": "function"

  }]

        

  async function upload(){
    window.web3 = await Moralis.enable()

    let contract = new web3.eth.Contract(abiContract, contractAddress)

     receipt = await contract.methods.createNewSpecies('svgsentfromBrowser',3,'browserszs',false).send({from: ethereum.selectedAddress, value:1000000000000000})

    console.log(receipt)

    }

  async function login() {

    let user = Moralis.User.current();

    if (!user) {user = await Moralis.Web3.authenticate();}

    console.log("logged in user:", user);

  }

  async function logOut() {

    await Moralis.User.logOut();

    console.log("logged out");

  }

  document.getElementById("btn-login").onclick = login;

  document.getElementById("btn-logout").onclick = logOut;

  document.getElementById("btn-create").onclick = upload;

  </script>

</body>

</html>

Wow, it works now! Thank you so much~!