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

6
  • 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) Nov 8, 2016 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 8, 2016 at 22:39
  • 1
    oraclize_query does charge from the contract balance the correct amount, according to the Oraclize API pricing: docs.oraclize.it/#pricing . That said, you can send like 0.01 ether along and any change will stay in your contract balance Nov 9, 2016 at 0: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: dapps.oraclize.it/browser-solidity/… Also browser-solidity doesn't require Metamask. You can send an amount of ether directly by browser-solidity.
    – user34
    Nov 22, 2016 at 17:28
  • I am facing the sam prob did you got a solution?
    – Sig Touri
    Jan 18, 2017 at 0:30

1 Answer 1

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.

Your Answer

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

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