[英]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. 我正在编写带有Solidity的简单智能合约,但显示了我无法修复的错误。 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: 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);
}
}
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.formatInput(web3.min。 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)
I tried to add something like personal.unlockAccount(web3.eth.defaultAccount)
but it doesn's fixed it. 我试图添加诸如
personal.unlockAccount(web3.eth.defaultAccount)
类的东西,但是它没有解决问题。
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 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 如果将web3js作为node_modules运行,则需要使用上述web3@0.18版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.