Git Product home page Git Product logo

oracle-eth's Introduction

Example that demonstrates an external Call from Solidity using Oracles

Dependencies:-

Solidity:

npm install -g truffle ethereumjs-testrpc npm install truffle-contract web3 bluebird fetch --save

For more details, refer the package.json file of the project.

If you're cloning this project for reference, issue npm install from the project root to install the dependencies.

Spring Boot:

Create a simple spring boot rest api [/rest/] that will simulate an api response.

Sample Code Snippet:

@RestController public class OracleController {

@GetMapping("/risk/{customerId}")
public String getCustomerRisk(@PathVariable String customerId) {
	System.out.println("Processing for customerId: " + customerId);
	return customerId.equals("C1") ? "OK" : "KO";
}

}

Truffle Config:

You can either use the testrpc to run the development blockchain at 8545 or configure Ganache/ ganache-cli at your preferred port.

Make sure the config is updated to the truffle config and oracle/ client js files

Steps to run the project and test the Oracle implementation:

  1. Issue truffle compile and truffle migrate command to compile and deploy the contract
  2. In a new terminal, run the oracle.js by issuing node oracle.js
  3. In a new terminal, run client.js by issuing node client.js [Repeat this step twice to notice the updates made to the customerRisk value]

*** Note: The simulation uses web3 to communicate with the oracle/ external API and the blockchain

For suggestions/ clarifications, please reach out to [email protected]

oracle-eth's People

Contributors

crpdev avatar

Watchers

 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.