Giter Site home page Giter Site logo

box's Introduction

Chainlink Truffle Box


Chainlink Truffle logo


Requirements

  • NPM

Installation

  1. Install truffle
npm install truffle -g
  1. Setup repo
mkdir MyChainlinkProject
cd MyChainlinkProject/
  1. Unbox
truffle unbox smartcontractkit/box
  1. Install dependencies by running:
npm install

# OR...

yarn install

Test

npm test

Deploy

If needed, edit the truffle-config.js config file to set the desired network to a different port. It assumes any network is running the RPC port on 8545.

npm run migrate:dev

For deploying to live networks, Truffle will use truffle-hdwallet-provider for your mnemonic and an RPC URL. Set your environment variables $RPC_URL and $MNEMONIC before running:

npm run migrate:live

You can also run:

truffle migrate --network live --reset

If you want to use truffle commands.

Helper Scripts

There are 3 helper scripts provided with this box in the scripts directory:

  • fund-contract.js
  • request-data.js
  • read-contract.js

In addition, for working with Chainlink Price Feeds and ChainlinkVRF there are folders respectively.

They can be used by calling them from npx truffle exec, for example:

npx truffle exec scripts/fund-contract.js --network live

The CLI will output something similar to the following:

Using network 'live'.

Funding contract: 0x972DB80842Fdaf6015d80954949dBE0A1700705E
0xd81fcf7bfaf8660149041c823e843f0b2409137a1809a0319d26db9ceaeef650
Truffle v5.0.25 (core: 5.0.25)
Node v10.16.3

In the request-data.js script, example parameters are provided for you. You can change the oracle address, Job ID, and parameters based on the information available on our documentation.

npx truffle exec scripts/request-data.js --network live

This creates a request and will return the transaction ID, for example:

Using network 'live'.

Creating request on contract: 0x972DB80842Fdaf6015d80954949dBE0A1700705E
0x828f256109f22087b0804a4d1a5c25e8ce9e5ac4bbc777b5715f5f9e5b181a4b
Truffle v5.0.25 (core: 5.0.25)
Node v10.16.3

After creating a request on a live network, you will want to wait 3 blocks for the Chainlink node to respond. Then call the read-contract.js script to read the contract's state.

npx truffle exec scripts/read-contract.js --network live

Once the oracle has responded, you will receive a value similar to the one below:

Using network 'live'.

21568
Truffle v5.0.25 (core: 5.0.25)
Node v10.16.3

TODO

  • Add tests for ChainlinkVRF
  • Add tests for Chainlink Price Feeds
  • Refactor tests to use this instead of defining contracts with let
  • Use the Chainlink-published mocks for MockV3Aggregator and VRFCoordinatorMock
  • Upgrade to Solidity 0.6.12 (to show that you don't have to use 0.6.6)

box's People

Contributors

thodges-gh avatar dependabot-preview[bot] avatar patrickalphac avatar alexroan avatar gmsteuart avatar dependabot[bot] avatar se3000 avatar henrynguyen5 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.