简体   繁体   中英

Solidity w/ Rinkeby Test Network | Uncaught Error: invalid address

I'm taking an intro to Blockchain class and am trying to deploy my project onto a web hosting site. When I execute my program locally, it works fine and metamask is able to process transactions properly. Upon putting my project up on the webhost, I get error:

Uncaught Error: invalid address

What can I do to fix this? Here is my JS: (Note: the init and metamask stuff was all written by my professor)

function init () {
  let button1 = document.querySelector ("#button1");
  button1.addEventListener ("click", buttonPress);
  let button2 = document.querySelector ("#button2");
  button2.addEventListener ("click", cashout);

  // load Demo1.abi.json obtained from the Compiler tab of Remix
  // (click the ABI button and save the clipboard contents to the file)
  fetch ("./countdown.abi.json")
    .then (function (response) {
      return response.json ();
    })
    .then (function (abi) {
      window.abi = abi;
    });
}
function getInstance () {
  let contractAddress = "hiddenContractAddress";
  if (contractAddress === "") {
    console.err ("no contract address set");
  }
  let factory = web3.eth.contract (window.abi);
  let instance = factory.at (contractAddress);
  return instance;
}

function buttonPress(evt) {
  let instance = getInstance ();
  let sender = web3.eth.accounts[0];
  instance.buttonClick ({
      from : sender,
      value : 100000000000000000,
      gas : 200000
    },
    function (error, result) {
      if (!error) {
        let currentwinner = document.querySelector ("#currentwinner");
        if (sender == currentwinner.value){
          window.alert("Unable to process transaction: You are already winning!");
          console.log(result);
        }
        else{
          window.alert("Your button press has been processed!");
          console.log(result);
        }
      } else {
        console.error (`get error: ${error}`);
      }
    }
  );
}


我想您应该使用另一个地址,而不是您测试时使用的本地地址。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM