Coder Social home page Coder Social logo

provable-things / ethereum-examples Goto Github PK

View Code? Open in Web Editor NEW
448.0 21.0 162.0 2.89 MB

Code examples showing how to use the Provable API on Ethereum

Home Page: https://docs.provable.xyz/#ethereum

Python 0.48% JavaScript 8.27% Solidity 91.00% Dockerfile 0.22% Shell 0.03%

ethereum-examples's Introduction

Provable Ethereum Examples Join the chat at https://gitter.im/oraclize/ethereum-api Info@Provable.xyz Contributions Welcome! HitCount

Here you can find some code examples showing just how easy it is to integrate the Provable Service into your Ethereum smart-contracts! Thanks to our Ethereum API using Provable in your projects couldn't be more straightforward. In Solidity it is as simple as inheriting the usingProvable contract like so:

    contract YourSmartContract is usingProvable {
        // … 
    }

This provisions your contract with the provable_query() function (and many others!), which makes it trivial to leverage our technology straight away. Head into the Solidity directory for more information.

πŸ’» Happy developing!


Serpent

πŸ’€ CAUTION: It is highly recommended to avoid using Serpent, especially in production. The examples herein have been left for reasons of posterity but support for it is no longer maintained as Serpent is considered outdated and audits have shown it to be flawed. Use them at your own risk!

ethereum-examples's People

Contributors

aviralwal avatar bertani avatar bertolo1988 avatar buffalodrew avatar d-nice avatar dependabot[bot] avatar gitmp01 avatar gitter-badger avatar gskapka avatar i-stam avatar marcogiglio avatar nya1 avatar riccardopersiani avatar shubhamtatvamasi avatar techcircus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ethereum-examples's Issues

Random number generation - contract deploymet failed

alp@mobby ~/proj/OGmobi/tr $ truffle migrate --reset
Compiling ./contracts/GetRandom.sol...
Compiling ./contracts/oraclizeAPI_0.4.sol...
Compilation warnings encountered:
..........
Running migration: 2_deploy_contracts.js
  Replacing GetRandom...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: VM Exception while processing transaction: invalid opcode
    at Object.InvalidResponse (/usr/lib/node_modules/truffle/build/cli.bundled.js:37022:16)
    at /usr/lib/node_modules/truffle/build/cli.bundled.js:210096:36
    at XMLHttpRequest.request.onreadystatechange (/usr/lib/node_modules/truffle/build/cli.bundled.js:208875:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/lib/node_modules/truffle/build/cli.bundled.js:210748:18)
    at XMLHttpRequest._setReadyState (/usr/lib/node_modules/truffle/build/cli.bundled.js:211038:12)
    at XMLHttpRequest._onHttpResponseEnd (/usr/lib/node_modules/truffle/build/cli.bundled.js:211193:12)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/truffle/build/cli.bundled.js:211153:24)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1047:12)

I tried to comment out different parts of code and finally got that error happens when line oraclize_setProof(proofType_Ledger); uncommented in code. Here is simples contract I tested:

pragma solidity ^0.4.11;

import "./oraclizeAPI_0.4.sol";

contract RandomExample is usingOraclize {

    event newRandomNumber(bytes);

    function RandomExample() {
        oraclize_setProof(proofType_Ledger); // sets the Ledger authenticity proof in the constructor
    }
}

No callback on Ropsten for query random source

Description

I write the contract and deploy it to Ropsten. My contract is base on random example.

I invoke my update() function 17 times to query the random source, but my callback function only invoke 15 times.

Has this happened in the MainNet?

Expected

It should invoke the callback of my contract for all query.

Actual

It does not invoke the callback of my contract for some query.

Detail

Crime scene

Contract address is 0x57d03068d25bb1d313b23cdf219fd68d9dd88f0f
TxHash is 0x1a64a68a40c57236db6728a974a9d81a21cf794484d3f52170009127e8c427d9
Query Id is 88d3d9873808e15514c6ac23e551bd407bf3a7b26282f96ce701afaf0d5e676e

Enviroment

  • Truffle v4.1.14 (core: 4.1.14)
  • Solidity v0.4.24 (solc-js)
  • NPM 6.4.1
  • Node.js v8.11.4
  • oraclize-api install by ethpm v1.0.0 truffle install oraclize-api

Code

Contract code on EtehrScan

pragma solidity 0.4.24;

import "../installed_contracts/oraclize-api/contracts/usingOraclize.sol";

contract RandomExample is usingOraclize {
    
    event Callback(bytes32 queryId, string result, uint256 number);
    event Update(bytes32 queryId);

    // _oracal is '0x0' on Ropsten and MainNet
    constructor(address _oracal) public payable {
        OAR = OraclizeAddrResolverI(_oracal);
        oraclize_setProof(proofType_Ledger);
        oraclize_setCustomGasPrice(0.02 szabo);
    }
    
    function __callback(bytes32 _queryId, string _result, bytes _proof) public { 
        require(msg.sender == oraclize_cbAddress(), "only oracal can generate random number");
        require(oraclize_randomDS_proofVerify__returnCode(_queryId, _result, _proof) == 0, "the proof verification has failed");
            
        uint256 maxRange = 2 ** (8 * 7);
        uint256 randomNumber = uint256(keccak256(abi.encodePacked(_result))) % maxRange;
        
        emit Callback(_queryId, _result, randomNumber);
    }
    
    function update() external {
        uint N = 1;
        uint delay = 0;
        uint callbackGas = 200000;
        bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas);
        emit Update(queryId);
    }

    function withdraw(uint256 _ammount) external {
        msg.sender.transfer(_ammount);
    }

    function() external payable {}
}

Reference

issue 9

Not getting Youtube views when using in private network with Ethereum-bridge

I have a 2 node private cluster running inside a docker container, I have used Ethereum bridge to deploy the connector contracts successfully on the network and following is the log from it -

bash-4.3# node bridge -a 9
Please wait...
[2017-12-20T05:59:56.273Z] INFO you are running ethereum-bridge - version: 0.5.5
[2017-12-20T05:59:56.281Z] INFO saving logs to: ./bridge.log
[2017-12-20T05:59:56.283Z] INFO using active mode
[2017-12-20T05:59:56.283Z] INFO Connecting to eth node http://localhost:8545
[2017-12-20T06:00:00.326Z] INFO connected to node type Geth/v1.7.3-stable-4bb3c89d/linux-amd64/go1.9.2
[2017-12-20T06:00:03.251Z] WARN Using 0xb1d3073bcc45462a3b0dfe69902cdd12971efec9 to query contracts on your blockchain, make sure it is unlocked and do not use the same address to deploy your contracts
[2017-12-20T06:00:03.797Z] INFO deploying the oraclize connector contract...
[2017-12-20T06:00:15.515Z] INFO connector deployed to: 0x41b0811e70d135540b0589bc578922995adb167d
[2017-12-20T06:00:16.105Z] INFO deploying the address resolver with a deterministic address...
[2017-12-20T06:00:53.519Z] INFO address resolver (OAR) deployed to: 0x6f485c8bf6fc43ea212e93bbf8ce046c7f1cb475
[2017-12-20T06:00:53.523Z] INFO updating connector pricing...
[2017-12-20T06:01:11.435Z] INFO successfully deployed all contracts
[2017-12-20T06:01:11.483Z] INFO instance configuration file saved to /root/oracle/ethereum-bridge/config/instance/oracle_instance_20171220T060111.json
[2017-12-20T06:01:11.486Z] INFO you are using a deterministic OAR, you don't need to update your contract
[2017-12-20T06:01:12.376Z] INFO Listening @ 0x41b0811e70d135540b0589bc578922995adb167d (Oraclize Connector)

I have modified the Youtube views code for the constructor to include the OAR as specified in the documentation and here is the code for it -

pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract YoutubeViews is usingOraclize {

    uint public viewsCount;

    function YoutubeViews() {
        OAR = OraclizeAddrResolverI(0x6f485c8bf6fc43ea212e93bbf8ce046c7f1cb475);      //add this line once using Oraclize in private chain environment
        update(0);
    }

    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) throw;
        viewsCount = parseInt(result, 0);
        // do something with viewsCount
        // (like tipping the author once viewsCount > X?)
        update(60*10); // update viewsCount every 10 minutes
    }

    function update(uint delay) {
        oraclize_query(delay, 'URL', 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(@class, "watch-view-count")]/text())');
    }

}

I am using Remix to deploy the contracts to my private network and everything went well, until I query the public viewscount value it always gives me 0. Not sure what going wrong here ?

truffle reports err "Error: The contract code couldn't be stored, please check your gas amount."

My contract is to generate rand number with oraclize. The code as follows:
_`pragma solidity ^0.4.11;
import "../node_modules/ethereum-api/oraclizeAPI.sol";

contract Orac is usingOraclize{

string public temperature = "hello,world";
uint256 public randNumber = 0;


function Orac() {
	OAR = OraclizeAddrResolverI(0x6f485c8bf6fc43ea212e93bbf8ce046c7f1cb475);
	oraclize_setProof(proofType_Ledger);
    update();
}

function __callback(bytes32 _queryId, string _result, bytes _proof) {
    if (msg.sender != oraclize_cbAddress()){
    	throw;
    }
    //temperature = result;
    // do something with the temperature measure..
    // if (oraclize_randomDS_proofVerify__returnCode(_queryId, _result, _proof) != 0) {
    //     // the proof verification has failed, do we need to take any action here? (depends on the use case)
    // } else {
    //     // the proof verification has passed
    //     // now that we know that the random number was safely generated, let's use it..
        
    //     // for simplicity of use, let's also convert the random bytes to uint if we need
    //     uint maxRange = 2**(8* 7); // this is the highest uint we want to get. It should never be greater than 2^(8*N), where N is the number of random bytes we had asked the datasource to return
    //     randNumber = uint(sha3(_result)) % maxRange; // this is an efficient way to get the uint out in the [0, maxRange] range
    // 	update();
    // }
}

function update() payable {
    //oraclize_query("WolframAlpha", "temperature in London");
    //oraclize_query(60, 'URL', 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(@class, "watch-view-count")]/text())');
    //oraclize_query("URL", "json(http://api.fixer.io/latest?symbols=USD,GBP).rates.GBP");
    uint N = 7; // number of random bytes we want the datasource to return
    uint delay = 0; // number of seconds to wait before the execution takes place
    uint callbackGas = 20000000; // amount of gas we want Oraclize to set for the callback function
    bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas);
}

function multi (uint256 x,uint256 y) public view returns(uint256) {
	return x*y;
}

function getTemp () public view returns(string) {
	return temperature;
}

}`
I depoloyed this contract to my private blockchain,the truffle report error as follow:
_Using network 'test'.

Running migration: 1_initial_migration.js
Replacing Orac...
... 0x613c44f231d2f25b022dd74c80c70bc76d60b85bfedd4c8551433ebd5e5b8f4f
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: The contract code couldn't be stored, please check your gas amount.
at Object.callback (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/contract.js:147:1)_

But if i delete the line "bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas);" in function update(),I could deploy the contract success.I know there is something wrong with the line.Someone can help me?Thanks!

Can't call update() in randomExample.sol more than once

I need to have a random number generated every 24 hours. I am able to use the randomExample.sol example (https://github.com/oraclize/ethereum-examples/blob/master/solidity/random-datasource/randomExample.sol) exactly as it is, but if I call update() again at the end of the __callback function , it always fails completely for me (no random number is generated even once).

This is my contract:

contract RandomExample is usingOraclize {
    
    event newRandomNumber_bytes(bytes);
    event newRandomNumber_uint(uint);
    
    uint public randomNumber;

    function RandomExample() {
        oraclize_setProof(proofType_Ledger); // sets the Ledger authenticity proof in the constructor
    }
    
    // the callback function is called by Oraclize when the result is ready
    // the oraclize_randomDS_proofVerify modifier prevents an invalid proof to execute this function code:
    // the proof validity is fully verified on-chain
    function __callback(bytes32 _queryId, string _result, bytes _proof)
    { 
        // if we reach this point successfully, it means that the attached authenticity proof has passed!
        if (msg.sender != oraclize_cbAddress()) throw;
        
        if (oraclize_randomDS_proofVerify__returnCode(_queryId, _result, _proof) != 0) {
            // the proof verification has failed, do we need to take any action here? (depends on the use case)
        } else {
            // the proof verification has passed
            // now that we know that the random number was safely generated, let's use it..
            
            newRandomNumber_bytes(bytes(_result)); // this is the resulting random number (bytes)
            
            // for simplicity of use, let's also convert the random bytes to uint if we need
            uint maxRange = 2**(8* 7); // this is the highest uint we want to get. It should never be greater than 2^(8*N), where N is the number of random bytes we had asked the datasource to return
            randomNumber = uint(sha3(_result)) % maxRange; // this is an efficient way to get the uint out in the [0, maxRange] range
            
            newRandomNumber_uint(randomNumber); // this is the resulting random number (uint)
            
            update();
        }
    }
    
    function update() payable {
        uint N = 7; // number of random bytes we want the datasource to return
        uint delay = 10; // number of seconds to wait before the execution takes place
        uint callbackGas = 1000000; // amount of gas we want Oraclize to set for the callback function
        bytes32 queryId = oraclize_newRandomDSQuery(delay, N, callbackGas); // this function internally generates the correct oraclize_query and returns its queryId
    }
    
}

Here update() should run every 10 seconds after being called, with the randomNumber variable updating each time. I am running update() as follows (sending 0.1 Ether and 1,000,000 Ether):

contractInstance.update({from: web3.eth.accounts[0], value:web3.toWei(0.1, "ether"), gas:1000000})

I was able to run the KrakenPriceTicker.sol contract which calls a function every 60 seconds, and am trying to use this randomExample.sol the same way, but with no success yet. I am using the Rinkeby test network if that's relevant. Any assistance appreciated.

Takes more than 30 minutes for query to be performed

I created the following contract to test your 'oraclize' functionaity:
https://ropsten.etherscan.io/address/0xdbe01bab0eecb80ec70f249825e775debd03c75b

I modified your 'KrakenPriceTicker', to have only one query performed immediately.

The etherscan report indicates that it took 37 minutes for your query to be performed (from 0xdc8f20170c0946accf9627b3eb1513cfd1c0499f).


The following contract requested a query to be performed today at 11:00am cst:
https://ropsten.etherscan.io/address/0x29b0d219e49f171a0434db9893a696939dfc0774

Here is the line of code that made that request:
oraclize_query(1516035600, "URL", "json(http://api.wunderground.com/api/51a133905ecec55c/conditions/q/37075.json).current_observation.temp_f");

It is now 12:00 noon cst, and the query has not been performed.

Use Local Memory Type Variable Instead of Global Storage Type Variable in Event to Save Gas

Hi, we recently have conducted a systematic study about Solidity event usage, evolution, and impact, and we are attempting to build a tool to improve the practice of Solidity event use based on our findings. We have tried our prototype tool on some of the most popular GitHub Solidity repositories, and for your repository, we find a potential optimization of gas consumption arisen from event use.

The point is that when we use emit operation to store the value of a certain variable, local memory type variable would be preferable to global storage type (state) variable if they hold the same value. The reason is that an extra SLOAD operation would be needed to access the variable if it is storage type, and the SLOAD operation costs 800 gas.

For your repository, we find that the following event use can be improved:

  • KrakenPriceTicker.sol
    function name: __callback
    event name:  LogNewKrakenPriceTicker
    variable:    priceETHXBT->_result
    function __callback(
        bytes32 _myid,
        string memory _result,
        bytes memory _proof
    )
        public
    {
        require(msg.sender == provable_cbAddress());
        update(); // Recursively update the price stored in the contract...
        priceETHXBT = _result;
        emit LogNewKrakenPriceTicker(priceETHXBT);
    }
  • WolframAlpha.sol
    function name: __callback
    event name:  LogNewTemperatureMeasure
    variable:    temperature->_result
    function __callback(
        bytes32 _myid,
        string memory _result
    )
        public
    {
        require(msg.sender == provable_cbAddress());
        temperature = _result;
        emit LogNewTemperatureMeasure(temperature);
        // Do something with the temperature measure...
    }
  • YoutubeViews.sol
    function name: __callback
    event name:  LogYoutubeViewCount
    variable:    viewsCount->_result
    function __callback(
        bytes32 _myid,
        string memory _result
    )
        public
    {
        require(msg.sender == provable_cbAddress());
        viewsCount = _result;
        emit LogYoutubeViewCount(viewsCount);
        // Do something with viewsCount, like tipping the author if viewsCount > X?
    }
  • WolframAlpha.sol
    function name: __callback
    event name:  LogNewTemperatureMeasure
    variable:    temperature->_result

  • CallerPaysForQuery.sol
    function name: __callback
    event name:  LogNewEthPrice
    variable:    ethPriceInUSD->_result

  • KrakenPriceTicker.sol
    function name: __callback
    event name:  LogNewKrakenPriceTicker
    variable:    priceETHXBT->_result

  • YoutubeViews.sol
    function name: __callback
    event name:  LogYoutubeViewCount
    variable:    viewsCount->_result

  • EncryptedQuery.sol
    function name: __callback
    event name:  LogNewRequestStatus
    variable:    requestStatus->_result

Do you find our results useful? Your reply and invaluable suggestions would be greatly appreciated, and are vital for improving our tool. Thanks a lot for your time!

Access & edit a file

Hi,
I'm currently working on an Accounting prototype based on smart contracts. Therefore I built a local ethereum blockchain, which needs access to a file/ an oracle. For this issue of getting off-chain data I found oraclize as a solution, but I'm struggeling with an implementation/ coding. I need to be able to read data of a file and also to delete some entries.Can you maybe give me a bit more introduction of how to implement such a case? Do you have something like a tutorial about that?

Thanks for your help!

Create examples alluded to in README.md

The following three in particular are popular use-cases for which examples would likely be popular (preferably w/ Truffle to demonstrate the testing &c.):

Coming Soon!

  • Nested queries!
  • Full query encryption!
  • Partial query encryption!

Solidity examples README proof-type mixup.

This line in the Ethereum Examples solidity dir's README.md...

Requesting TLSNotary authenticity proofs! #1

... links via the #1 to the kraken example, which uses an Android proof, not TLSN!

multiple result values of different attributes in a request

Hi,

as title, I could get the correct result from website. But the callback function won't get any result, and the balance of the contract not be changed.

the api url, https://api.etherscan.io/api?module=proxy&action=eth_getTransactionByHash&txhash=0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1&apikey=YourApiKeyToken

The result json format is:
{"jsonrpc":"2.0","id":1,"result":{"blockHash":"0xf64a12502afc36db3d29931a2148e5d6ddaa883a2a3c968ca2fb293fa9258c68","blockNumber":"0x70839","from":"0xc80fb22930b303b55df9b89901889126400add38","gas":"0x30d40","gasPrice":"0xba43b7400","hash":"0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1","input":"0xfc36e15b0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a4861636b65726e65777300000000000000000000000000000000000000000000","nonce":"0xa7","to":"0x03fca6077d38dd99d0ce14ba32078bd2cda72d74","transactionIndex":"0x0","value":"0x0","v":"0x1c","r":"0xe7ccdba116aa95ae8d9bdd02f619a0cdfc1f60c5740b3899865822a80cd70218","s":"0xf200df1921ea988d16280a0873b69cb782a54e8a596d15e700710c820c8d2a9e"}}

I want the results are hash, input, blockNumber...
I've tried ...result[hash, input], but it doesn't work.

Nothing is working

When I use the oraclize API I get hundreds of errors. This is when I just copy paste your examples in remix...

One example is Potential Violation of Checks-Effects-Interaction pattern in usingOraclize.oraclize_query(uint256,string memory,string memory[] memory): Could potentially lead to re-entrancy vulnerability.
Note: Modifiers are currently not considered by this static analysis.

How to speed up the service

Tell me a sore question, how to maximize the return of the value by the oracle as much as possible; we are developing a fair game on the blockchain and it is extremely important for us to make it quick, using the oracle we get a delay of at least a minute. Gas price 20gwei.

Random datasource example allows ransoming winning players

Given the restriction to submit query results only for Oraclize in the exemplary implementation:

https://github.com/oraclize/ethereum-examples/blob/e7f364bb104f0b79eeb1eaec9fb4b7bb316d1cd5/solidity/random-datasource/randomExample.sol#L26

the described ransoming mechanism in the paper is possible. Simple solution would be to remove that line. To quote the paper

Since only valid result will be executed, there is no need to limit the access only to the data carrier.

Oraclize not returning data when using example contract

I am trying to use the example Oraclize contracts, including KrakenPriceTicker.sol. Here's my contract (modified very slightly - including pointing it to oraclizeAPI_0.4.sol, since oraclizeAPI.sol as the contract in the repository tries to import is a blank contract now):

pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI_0.4.sol";

contract KrakenPriceTicker is usingOraclize {

    string public ETHXBT;
    uint public timesCalled;
    uint public timesFailed;

    event newOraclizeQuery(string description);
    event newKrakenPriceTicker(string price);


    function KrakenPriceTicker() payable {
        oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
    }

    function __callback(bytes32 myid, string result, bytes proof) {
        ETHXBT = result;
        newKrakenPriceTicker(ETHXBT);
        update();
    }

    function update() payable {
        if (oraclize_getPrice("URL") > this.balance) {
            newOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee");
            timesFailed++;
        } else {
            newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
            oraclize_query(60, "URL", "json(https://api.kraken.com/0/public/Ticker?pair=ETHXBT).result.XETHXXBT.c.0");
            timesCalled++;
        }
    }

}

When the update() function is called and some ether and gas sent with it, it should call the kraken.com api and update the value of ETHXBT with what's returned. However, the value of ETHXBT is always blank. I know the oraclize_query is being called, or at least it passes that line, because the timesCalled variable does increment. Going directly to https://api.kraken.com/0/public/Ticker?pair=ETHXBT shows there shouldn't be any problem.

I've deployed the above contract at https://ropsten.etherscan.io/address/0x2c51daecf702f2afe3abee2cc84570ee17f75650 (I've tried to call update() several times, including by sending 0.1 ether).

Is there a problem with the random number now or is there a problem with my use

After I deployed the
https://github.com/provable-things/ethereum-examples/blob/master/solidity/random-datasource/randomExample.sol
file, I clicked update and prompted
Gas estimation errored with the following message (see below) . The transaction execution will likely fail. Do you want to force sending?gas required exceeds allowance (8000029) or always failing transaction

I have deployed on both ropsten and kovan networks, and the relaxed-commit has the same problem. Why?

Web3.providers with httpProvider

I have see all provable-things/ethereum-examples/solidity/truffle-examples/ are in the js this variable
const web3 = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:9545'))

Can we have any example with Web3.providers.HttpProvider('http://localhost:9545'))
I cant use in my node websocket and i need to use oraclizeAPI.sol.

Thx a lot‘‘‘‘
BelΓ©n.

always failing transaction Bitcoin Balance

Expected behavior

On Remix, I am attempting to read the BTC balance of 3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r (which is~ 0.0257) using your BitcoinBalanceExample file

Actual behavior

I am run getBalance on Remix I receive

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
gas required exceeds allowance (10000000) or always failing transaction

To reproduce

  1. copy the BitcoinBalanceExample.sol file and paste it in Remix.
  2. make sure the compiler is set to 0.5.17
  3. replace import "./provableAPI.sol"; with import "github.com/oraclize/ethereum-api/provableAPI.sol";
  4. compile with Enable optimization enabled
  5. connect MetaMask to Remix on the Rinkeby testnet
  6. Deploy the contract
  7. Go to newly deployed contract and enter 3D2oetdNuZUqQHPJmcMDDHYoqkyNVsFk9r for getBalance
  8. Once you attempt to run the function, you will receive the error message above

Update Truffle examples READMEs

...to reflect the new stable release of Truffle 5.


Possible better way to achieve above:

Have Truffle 5 in the package.json & recommend running Truffle via npx after an npm install.

βž• Pros :

  • We don't have to overwrite user's globally installed versions of Truffle (if they have any).
  • We can now control & pin the Truffle version used via package.json.

βž– Cons:

  • Fewer people know about npx magic.
  • Truffle docs themselves recommend the global install.

Example using random.org

Could you please add example which uses https://www.random.org/ to get random numbers?

I've tried to make contract, but can't make it work somehow. I've tried that with Ethereum Studio on sandboxed network, with Oraclize plugin.

This is what my contract looks like.

import "lib/std.sol";
import "lib/oraclizeAPI.sol";

contract Contract is named("Contract"), mortal, usingOraclize {

  uint256 public randomInt;
  event onCallback(string result);

  function Contract() {
    oraclize_setNetwork(networkID_consensys);
  }

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

  function update() {
    oraclize_query("URL", "json(https://api.random.org/json-rpc/1/invoke).result.random.data.0", '{"jsonrpc":"2.0","method":"generateIntegers","params":{"apiKey":"<ENTER API KEY HERE>","n":1,"min":1,"max":10,"replacement":true,"base":10},"id":458}');
  }
}

Don't forget to replace with your random.org apiKey. https://api.random.org/api-keys/beta

__callback is called, but string result is always empty.

Not sure if mistake is in my code or oraclize or Ethereum Studio Oraclize plugin.

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.