개인 RPC 서버에 계약을 연결하려고합니다. 내 html 페이지의 카운터 매개 변수를 업데이트 할 수 있고, 그러면 내 견고한 계약 파일과 브라우저의 업데이트를 참조 할 수 있습니다. 그러나, 나는 내 HTML 파일에 대한 다음과 같은 오류로 계속 실행. index.html과 contract.sol에도 아래 내용이 포함되어 있습니다. 타이!Web3 콜백 기능 - 고 가용성 문제
<!doctype html>
<html>
<head>
<title>myDapp</title>
<script src="web3.js/dist/web3.min.js"></script>
<script type="text/javascript">
var contract_address = "0x68FDbd58D28BeD866E07906f6129bAC86161e243";
var contract_abi = [ { "constant": true, "inputs": [], "name": "getCreator", "outputs": [ { "name": "", "type": "address", "value": "0xc0f0fb70a63e7b345932da8eb427463f586be95d" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "kill", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [ { "name": "myNewNumber", "type": "uint256" } ], "name": "setMyNumber", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "getMyNumber", "outputs": [ { "name": "", "type": "uint256", "value": "3" } ], "payable": false, "stateMutability": "view", "type": "function" }, { "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" } ];
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
var contract_instance = web3.eth.contract(contract_abi).at(contract_address);
console.log(contract_instance);
function getCounter() {
document.getElementById("myCounter").innerText = contract_instance.getMyNumber().toNumber().call;
}
</script>
</head>
<body>
<h1>Interact with a contract</h1>
<button onclick="getCounter()">Update Counter</button>
<button onclick="increaseCounter()">Increase Counter</button>
<span id="myCounter"></span> Counter
</body>
</html>
contract.sol
pragma solidity ^0.4.15;
contract MyContract {
address creator;
uint256 myNumber;
function MyContract() public {
creator = msg.sender;
myNumber = 3;
}
function getCreator() public constant returns(address) {
return creator;
}
function getMyNumber() public constant returns(uint256) {
return myNumber;
}
function setMyNumber(uint256 myNewNumber) public {
myNumber = myNewNumber;
}
function kill() public {
if(msg.sender == creator) {
selfdestruct(creator);
}
}
}
[** 코드 또는 오류 이미지를 게시하지 마십시오. **] (https://meta.stackoverflow.com/q/303812/995714) 이미지 및 스크린 샷은 게시물에 추가 할 수 있지만 그 글이 없으면 게시물이 여전히 분명하고 유용하다는 것입니다. 코드 이미지 나 오류 메시지를 게시하는 경우 실제 코드/메시지를 직접 복사하여 붙여 넣거나 입력하십시오. – Rob