简体   繁体   中英

Uncaught Error: invalid address at u (web3.min.js:1)

I am writing an simple Smart Contract with Solidity but it shows an error I can't fix. Here is my code:

<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>

Skript:

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

The Solidity-Code is simple:

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

}

In the console it shows the error:

Uncaught Error: invalid address at u (web3.min.js:1) at inputCallFormatter (web3.min.js:1) at web3.min.js:1 at Array.map () at i.formatInput (web3.min.js:1) at i.toPayload (web3.min.js:1) at _.e [as call] (web3.min.js:1) at c.call (web3.min.js:1) at c.execute (web3.min.js:1) at index.html:85

I tried to add something like personal.unlockAccount(web3.eth.defaultAccount) but it doesn's fixed it.

You need to provide the address of the deployed smart contract.

You will get smartcontract address while deploying the smart contract. you need to with use the same network what you used to deploy.

For Reference

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

if you running web3js as node_modules you need to use the above web3@0.18 version

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