node.js - Uncaught Error :u处的地址无效(web3.min.js:1)

标签 node.js blockchain ethereum solidity

我正在用Solidity编写一个简单的智能合约,但是它显示了我无法修复的错误。这是我的代码:

<div class="container">

    <h1>Information</h1>

    <h2 id="form"></h2>

    <label for="name">Name</label>
    <input id="name" type="text">

    <label for="name">Age</label>
    <input id="age" type="text">

    <button id="button">Update Infomation</button>


</div>


斯克里普特:

if (typeof web3 !== 'undefined') {
        web3 = new Web3(web3.currentProvider);
    } else {
       web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
    }

    web3.eth.defaultAccount = web3.eth.accounts[0];

    var SmartContract = web3.eth.contract(ABI);

    var ContractAddress= SmartContract.at(Address);

    ContractAddress.getInformation(function(error, result){
       if(!error)
           {
               $("#form").html(result[0]+' ('+result[1]+' years old)');
               console.log(result);
           }
       else
           console.log(error);
   });

   $("#button").click(function() {
       ContractAddress.setInformation($("#name").val(), $("#age").val());
   });


Solidity-Code很简单:

contract information{

   string fName;
   uint age;

   function setInformation(string _fName, uint _age) public {
       fName = _fName;
       age = _age;
   }

   function getInformation() public constant returns (string, uint) {
       return (fName, age);
   }

}


在控制台中,它显示错误:


  未捕获的错误:在i.formatInput(web3.min。)处Array.map()的web3.min.js:1处inputCallFormatter(web3.min.js:1)在u(web3.min.js:1)处的无效地址。 js.1)位于_.e的i.toPayload(web3.min.js:1),位于c.call(web3.min.js:1)处于[调用时](web3.min.js:1)。在index.html:85执行(web3.min.js:1)


我试图添加类似personal.unlockAccount(web3.eth.defaultAccount)的内容,但它没有解决问题。

最佳答案

您需要提供已部署的智能合约的地址。

部署智能合约时,您将获得智能合约地址。您需要使用与部署相同的网络。

以供参考

https://github.com/praveenkakumanu/Ethereum/blob/master/sample/index.html

如果将web3js作为node_modules运行,则需要使用上述web3@0.18版本

关于node.js - Uncaught Error :u处的地址无效(web3.min.js:1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53026251/

相关文章:

node.js - 如何访问 promise 中的值(value)?

javascript - 如何使用 watch 依次运行多个 NPM 脚本

python - 如何将 python 依赖项添加到 heroku Node 服务器?

ruby-on-rails - Rails 上的区 block 链去中心化数据库

docker - 使用 docker 镜像手动启动 super 账本节点

以太坊DAPP——了解

javascript - 然后在 Javascript 中使用外部变量

blockchain - 使用 BNB 从合约购买代币时出现问题

node.js - 发送以太坊交易,Web3.js没有源地址,但有源私钥?

npm - typechain --target ethers-v5 不被识别为内部命令