13

Here is my smart contract that uses oraclize to buy bitcoin with ether.

pragma solidity ^0.4.0;

import "https://github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol";

contract BuyBitcoin is usingOraclize {

    address owner;
    string public temp;


    function BuyBitcoin() {
        owner = msg.sender;

        OAR = OraclizeAddrResolverI(0x51efaf4c8b3c9afbd5ab9f4bbc82784ab6ef8faa);
        update();
    }

    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) throw;
        result;
    }

    function update() payable {
        oraclize_query("URL", "json(https://www.shapeshift.io/shift).orderId", '{"withdrawal":"3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy", "pair":"eth_btc" , "amount" : 1000}');
    }

    function kill(){
        if (msg.sender == owner) suicide(msg.sender);
    }

}

Update :

I'm sending 0.01 ether as part of transaction enter image description here

I can compile the contract but when I attempt to run the update function I receive 'VM Exception: invalid JUMP'

Have I omitted something with my contract ?

and using Javascript VM :

enter image description here

Have I missed a step ?

I'm using metamask and have ether in account :

enter image description here

eth
  • 85,679
  • 53
  • 285
  • 406
blue-sky
  • 261
  • 1
  • 10
  • 1
    Hi, Thomas from Oraclize here. The "OAR" custom definition (the one you have in the constructor) is needed only when using it within the browser-solidity "Ethereum VM" mode (in-memory execution). You must remove it when running it on a real blockchain. Also, are you sending any value along the update() call? The first oraclize_query is free, but the others come at a cost (even when simulated) – Thomas Bertani Nov 08 '16 at 16:14
  • 1
    @Thomas Bertani no I'm not sending any value included with update() call. How much ether do I need to send per call ? – blue-sky Nov 08 '16 at 22:39
  • 1
    oraclize_query does charge from the contract balance the correct amount, according to the Oraclize API pricing: http://docs.oraclize.it/#pricing . That said, you can send like 0.01 ether along and any change will stay in your contract balance – Thomas Bertani Nov 09 '16 at 00:06
  • @blue-sky are you deploying the contract on-chain? If not, and you are doing only in-memory execution, you are not using the correct browser-solidity. Oraclize has a patched with support for oraclize queries and callbacks at this URL: http://dapps.oraclize.it/browser-solidity/#version=soljson-v0.3.6+commit.3fc68da.js&optimize=true&gist=0423a99a481bbe15d0b233cdd111c9e5 Also browser-solidity doesn't require Metamask. You can send an amount of ether directly by browser-solidity. –  Nov 22 '16 at 17:28
  • I am facing the sam prob did you got a solution? – Sig Touri Jan 18 '17 at 00:30
  • @SigTouri unfortunately no I did not find a solution to this but I feel I do not understand the ethereum ecosystem sufficiently in order to understand the problem. – blue-sky Jan 18 '17 at 13:40

1 Answers1

1

It may be a bit late to get an answer for this. Probably you might be having an answer with you.

So here's my take on this problem. when you use solidity version ^0.4.0 and try to send value to the contract, 0.01 Ether in your case, you must use the default function provided in the solidity and use payable keyword as well.

This issue is most commonly being faced for those, who try to pull off similar stuff. Try doing that once.

Hope the observation helps.

Thanks.

Vixon
  • 557
  • 4
  • 8