2

I try to deploy a contract using truffle to my private ethereum network using geth and i get this error gas required exceeds allowance (6721975) or always failing transaction. I have create an account and i have mined with this. I also have connected it with metamask. What i have to do to solve it?

genesis.json

{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"nonce": "0x0000000000000042",
"mixhash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x200",
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash":
"0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0xffffffff",
"alloc": {
}
}

contract

pragma solidity 0.5.8;

contract Creation {
    // Model a Candidate
    struct Candidate {
        uint id;
        string name;
        uint voteCount;
    }

    // Store accounts that have voted
    mapping(address => bool) public voters;
    // Store Candidates
    // Fetch Candidate
    mapping(uint => Candidate) public candidates;
    // Store Candidates Count
    uint public candidatesCount;

    // voted event
    event votedEvent (
        uint indexed _candidateId
    );

    constructor () public {
        addCandidate("Candidate 1");
        addCandidate("Candidate 2");
    }

    function addCandidate (string memory  _name) private {
        candidatesCount ++;
        candidates[candidatesCount] = Candidate(candidatesCount, _name, 0);
    }

    function vote (uint _candidateId) public {
        // require that they haven't voted before
        require(!voters[msg.sender]);

        // require a valid candidate
        require(_candidateId > 0 && _candidateId <= candidatesCount);

        // record that voter has voted
        voters[msg.sender] = true;

        // update candidate vote Count
        candidates[_candidateId].voteCount ++;

        // trigger voted event
        emit votedEvent(_candidateId);
    }
}

2 Answers 2

1

Having the max gas consumed usually means that the contract construction function throws or reverts. But the question does not have enough details to tell.

Maybe you can edit the question and add your contract code and what commands you use to deploy it.

8
  • I edit it and i use truffle . so truffle migrate --reset is the commaand that i use
    – Panos Kor
    Jul 1, 2019 at 14:44
  • Does it deploy if you remove addCandidate("Candidate 1"); lines from constructor? Jul 1, 2019 at 15:09
  • Actually you can test it by trying to deploy an empty contract... then you see if the problem is with your contract code or something else in your deployment. Jul 1, 2019 at 15:10
  • Well, i test is empty and it;s ok ..so is smoething wrong with the code? I deployed it with ganache and it runs with out problem. Why in my private networ(geth) cant run?
    – Panos Kor
    Jul 1, 2019 at 16:36
  • I removed also the addCandidate("Candidate 1"); but doesnt work
    – Panos Kor
    Jul 1, 2019 at 16:37
0

Finally i have to write in the web3provider "localhost:port" and not the ip of my node

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.