1

I try interect with contract. I use this tutorial and this.

I deploed this contract in ropsten testnet by address: 0xF55F55d2b15949ae78a34478CF356D9fF8bB0629. I can read counter value. But I can`t increse counter. I have error as: enter image description here

This is code of my script in html file:

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Interect with contract</title>
    <script src="js/web3.js">
    </script>
</head>

<body>

    <h1>Interact with contract</h1>

    <button onclick="getCounter()">UpdateCounter</button>
    <button onclick="increaseCounter()">IncreaseCounter</button>
    <span id="myCounter"></span>
    <script type="text/javascript">
        var contractAddress = "0xF55F55d2b15949ae78a34478CF356D9fF8bB0629"; //in ropsten

        var contractAbi = [{
                "constant": true,
                "inputs": [],
                "name": "getCreator",
                "outputs": [{
                    "name": "",
                    "type": "address"
                }],
                "payable": false,
                "type": "function"
            },
            {
                "constant": false,
                "inputs": [],
                "name": "kill",
                "outputs": [],
                "payable": false,
                "type": "function"
            },
            {
                "constant": false,
                "inputs": [{
                    "name": "myNewNumber",
                    "type": "uint256"
                }],
                "name": "setMyNumber",
                "outputs": [],
                "payable": false,
                "type": "function"
            },
            {
                "constant": true,
                "inputs": [],
                "name": "getMyNumber",
                "outputs": [{
                    "name": "",
                    "type": "uint256"
                }],
                "payable": false,
                "type": "function"
            },
            {
                "inputs": [],
                "payable": false,
                "type": "constructor"
            }
        ];

        web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/some")); //connect with a Ropsten Test Net or use http://localhost:8545 
        // web3 = new Web3(web3.currentProvider);

        var contractInstance = web3.eth.contract(contractAbi).at(contractAddress); //instance of contract nesessary to access the contract

        function getCounter() {
            document.getElementById("myCounter").innerText = contractInstance.getMyNumber().toNumber();
        }


        function increaseCounter() {
            var currentNumber = contractInstance.getMyNumber().toNumber();
            currentNumber++;

            web3.personal.unlockAccount('0x959fd7ef9089b7142b6b908dc3a8af7aa8ff0fa1', "some");

            contractInstance.setMyNumber(
                currentNumber, {
                    from: '0x959fd7ef9089b7142b6b908dc3a8af7aa8ff0fa1',
                    gas: 2000000
                },
                function (error, result) {
                    if (error) {
                        console.error(error);
                    } else {
                        var txHash = result;
                        console.log(txHash);
                    }
                });
        }
    </script>
</body>
</html>

I don`t use geth. Is it possible to do without using geht? How can I fix error?

marked as duplicate by Ismael, Achala Dissanayake, Richard Horrocks, Badr Bellaj Oct 16 '17 at 15:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.