Skip to content

Latest commit

 

History

History
100 lines (59 loc) · 3.44 KB

README.md

File metadata and controls

100 lines (59 loc) · 3.44 KB

🔏 Provable-Zeppelin

 

A Provable & ZeppelinOS collaboration showing you how to use Provable alongside ZeppelinOS in order to create data-rich smart-contracts leveraging external APIs!

This example shows you how to deploy a simple crowdsale contract which uses Provable to discover the price of ETH in USD in order to correctly set the price for the tokens you're selling to $1!

 


👉 How to use:

Pre Flight Checks) You will need Node, NPM & a browser with Metamask installed!

1) First install the Open Zeppelin CLI, Truffle & Ganache globally:

❍ npm i -g @openzeppelin/cli@2.5.1 truffle@5.0.2 ganache-cli@6.3.0

2) Now unpack this starter kit in an empty directory:

❍ openzeppelin unpack provable-things/provable-starter-kit

3) Next, fire up a new terminal & start up a local blockchain instance with Ganache via:

❍ ganache-cli --secure -u 0 -u 1 -u 2 --deterministic

4) Then in the root of the repo run the setup script:

❍ npm run setup

5) Then use the Open Zeppelin CLI initialize your project:

❍ openzeppelin init provable-starter-kit

6) Now enter the client directory and run the React app:

❍ cd client && npm run start

7) Once the React app is built you can view it on your localhost by pointing your browser at:

❍ http://localhost:3000

9) Now in your browser you should see that your Provable Starter-kit is up & running! Click on Provable Crowdsale in the top right corner to begin creating the example dapp!

💻 Happy Developing!

 


📃 Smart-Contract Test Instructions

In order to run the smart-contract tests you will need to use the ethereum-bridge to provide a way for the Provable service to listen to events from your locally-based smart-contract(s). To get it up and running:

1) Enter this directory & install dependencies:

❍ npm i

2) Launch the Truffle develop console:

❍ npx truffle develop

3) Open a new console in the same directory & spool up the ethereum-bridge:

❍ npx ethereum-bridge -a 9 -H 127.0.0.1 -p 9545 --dev

4) Once the bridge is ready & listening, go back to the first terminal where you have the Truffle development console running & set the tests going:

❍ truffle(develop)> test


  Contract: ❍ Provable Zeppelin Example
    ❍ Crowdsale Tests
      ✓ Should deploy a token (136ms)
      ✓ Should deploy the Provable Zeppelin Crowdsale Contract (139ms)
      ✓ Should give the crowdsale contract all the tokens (71ms)
      ✓ Should get web3 instantiation of contract to listen for events
      ✓ Owner can't init crowdsale before getting ETH price
      ✓ Non-owner can't get eth prices via Provable
      ✓ Should get ETH price in cents (6789ms)
      ✓ Should have stored ETH price in cents in contract
      ✓ Non-owner can't init crowdsale even if ETH price retrieved (38ms)
      ✓ Crowdsale should not yet be initialized
      ✓ Should successfully init crowdsale (46ms)
      ✓ Crowdsale should now be initialized (71ms)
      ✓ Should have set price per token in crowdsale contract
      ✓ Should have calculated price per token in wei correctly
      ✓ Should not be able to buy < 1 token (65ms)
      ✓ Should be able to buy a token (89ms)
      ✓ Should refund any change from buying tokens (100ms)


  17 passing (9s)

truffle(develop)>