Code Monkey home page Code Monkey logo

eth-oracle's Introduction

eth-oracle

Bluzelle-Ethereum integration for Apr. 28th hackathon, provided as a Solidity file that implements a wrapper around Oraclize.

Importing

To use Bluzelle in a solidity contract, first import bluzelle.sol. If you are using remix, you can do this with just

import "https://github.com/bluzelle/eth-oracle/bluzelle.sol";

If you are using an environment which doesn't handle that for you, you may have to download bluzelle.sol directly as well as its dependancies:

https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.4.sol https://github.com/Arachnid/solidity-stringutils/blob/master/src/strings.sol

Usage

To use the Bluzelle interface, first have your contract extend BluzelleClient

contract MyContract is BluzelleClient {
  ...
}

Call setUUID(string uuid) before making any DB calls - this configures which distinct database you connect to. Your UUID may actually be any string, but you should choose it to be something distinct from anyone else's - such as your contract's address, a random string, or actually a uuid.

Then, DB operations are performed with the following methods:

create("a key", "with some data");
read("a key");
update("a key", "with a new value");
remove("a key");

Each DB operation will consume a small amount of ether to pay Oraclize's fee.

All database operations are performed asynchronously (this is a fundamental constraint of running in Ethereum). If you want to act on the result of your database operations (and presumably you do, at least for reads), then override some or all of the following callback methods

// When a read succeeds
function readResult(string key, string result) internal { ... }

// When a read fails
function readFailure(string key) internal {...}

// When a create, update, remove is performed
function createResponse(string key, bool success) internal {...}
function updateResponse(string key, bool success) internal {...}
function removeResponse(string key, bool success) internal {...}

The included file sample.sol shows an example smart contract that excercises this functionality.

Caveats

This should work on any network Oraclize supports: Ropsten, Kovan, and Rinkeby as well as the main net. We do not recommend it for use on the main net; it's not known to be reliable or secure enough.

Each database transaction requires a small fee for Oraclize ($0.01 usd worth), and the transaction will fail if the contract balance is too low.

If you neglect to set a UUID before making a DB call, you will end up using the emptry string as your UUID. This may result in Bad Things.

eth-oracle's People

Contributors

isabelsavannah avatar

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.