14

I wrote what I thought was a dead simple contract - a saving jar... you add value ("save") into the jar and when the balance of the contract reaches a certain amount ("target"), then I am able to withdraw the value. But whenever I try to send it value, it errors with "Bad Jump Destination"

Here is my contract:

pragma solidity ^0.4.0;

contract jar {
  uint public target;
  uint public numDonations;

  function jar (uint _target) {
    target = _target;
    numDonations = 0;
  }

  function save() {
    numDonations++;
  }

  function getBalance() constant returns (uint) {
    return this.balance;
  }

  function withdraw () {
     if (this.balance < target) throw;
     if (!msg.sender.send(this.balance)) throw;
  }
}

And here is the save command I am sending:

jar.save({from:eth.accounts[0], value: 100000000000000000, gas:3000000}) 

Here is an example of a failed transaction:

https://testnet.etherscan.io/tx/0xcf93aa967f6d1d42b84147511ab58a66a468ee8a102a8d78f78f071ec1a30a05

I have never seen this error before and I am totally stumped. Any pointers would be greatly appreciated.

12

While you are using Solidity 0.4 you should define your payable function. if your contract will receive Etheres define in your code payable fallback:

function() payable {}

if you want any functions will accept Ethers it should be declared with a payable modifier

function save() payable {
    numDonations++;
  }
  • In particular, for this example, it should be function save() payable{...} – Tjaden Hess Jan 13 '17 at 16:22

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.