【问题标题】:Solidity w/ Rinkeby Test Network | Uncaught Error: invalid address带有 Rinkeby 测试网络的 Solidity |未捕获的错误:地址无效
【发布时间】:2020-03-13 19:44:38
【问题描述】:

我正在介绍区块链课程,并正在尝试将我的项目部署到一个网络托管站点上。当我在本地执行我的程序时,它工作正常,并且 metamask 能够正确处理事务。将我的项目放在虚拟主机上后,出现错误:

未捕获的错误:地址无效

我能做些什么来解决这个问题?这是我的 JS: (注:init 和 metamask 的东西都是我教授写的)

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}`);
      }
    }
  );
}


【问题讨论】:

    标签: javascript html ethereum solidity metamask


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-28
      • 2019-10-07
      • 2019-06-09
      • 2018-11-07
      • 1970-01-01
      • 2021-12-16
      • 2016-12-30
      • 2020-08-18
      相关资源
      最近更新 更多