1

I have created Ethereum Private Network and mined sufficient ether.I have deployed a Smart Contract 'Hello World' and tried to execute the functions in the deployed contract.

But the contract won't get executed due to low gas.

Ethereum Wallet showing ether mined

Contract Execution in Wallet shows the out of gas error

I have included the contract code for your reference.

pragma solidity ^0.4.2;

contract HelloWorld {
    uint public balance;

    function HelloWorld(){
             balance=1000;
    }
    function deposit(uint _value) returns (uint _newValue){
             balance += _value;
             return balance;    
    }
}

I have successfully executed this contract using browsersolidity and truffle. But it won't get executed using Ethereum Wallet.

  • The wallet has looked at the contract and concluded it will probably throw an exception. It's doing the user a favor by warning about it before the attempt. Please post your contract code. Someone should be able to spot the problem. – Rob Hitchens - B9lab Jan 4 '17 at 8:55
  • @Rob Hitchens I have updated the question.But the contract is successfully executed using browsersolidity and truffle. – Crissi Mariam Robert Jan 4 '17 at 9:45
1

After solidity 0.4.0 you need to specify "payable" for any function that will receive either. It prevents ether sent to functions that don't expect it and don't know how to handle it. As you might have guessed, sending to non-payable functions throws like you're seeing.

I don't see an obvious reason why your existing contract won't execute as long as you're not sending value with the message. Probably worth exploring.

As an alternative, I added payable so you can actually transfer either (There appears to be 4 sent in the screen shot) without the exception. Also adjusted the parameters and internals slightly so the "value" is the actual value received.

pragma solidity ^0.4.2;

contract HelloWorld {
    uint public balance;

    function HelloWorld(){
             balance=1000;
    }
    function deposit() payable returns (uint _newValue){
             balance += msg.value;
             return balance;    
    }
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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