This is a workshop project that uses Chainlink to implement secure, decentralized payment-on-delivery. This project is built on top of Chainlink Dev.
The goal of this project is to allow the user to go from a bare development setup (Docker, Ganache, etc) to deploying a
fully sandboxed, fully functional Chainlink network in a single command. Run the npm start
command to achieve the
following:
- Migrate a
LINK
token, Chainlink oracle and Chainlink client smart contract to Ganache with Truffle. - Deploy a local, pre-configured Chainlink node with Docker. The Chainlink node will be connected to Ganache.
- Deploy a Chainlink external adapter locally with Docker.
- Perform the following tasks with Truffle scripts:
- Fund the Chainlink client smart contract with 100
LINK
tokens. - Set fulfillment permission to
true
for your Chainlink node on your oracle smart contract. - Fund the Chainlink node with 1
ETH
. - Add jobs to the Chainlink node, including one that exercises the external adapter.
- Configure the Chainlink client smart contract to use the jobs on the Chainlink node.
- Fund the Chainlink client smart contract with 100
This project is intended for development purposes only. A number of the configuration settings used by this project should never be deployed in a production setting.
As of 2019-11-18 this project is still in a rather unpolished state and has only been tested on Linux.
In addition to the dependencies described in the package.json
file, this project is also dependent
upon Docker/Docker Compose, Ganache and possibly others.
In order to exercise the external adapter capabilities, you will need to provide an API key for the EasyPost API.
- Run
npm i
to install dependencies. - Update the
API_KEY
key value in theadapters/easypost/.env
file to reflect the value of your EasyPost API key. - Create a new workspace in Ganache:
- On the
Workspace
tab, addtruffle/truffle-config.js
from this project. - On the server tab, select the
0.0.0.0 - All Interfaces
hostname. - Save the workspace.
- On the
- Run
npm start
to perform the steps described above. - Run
npm run chainlink:logs
to view the Chainlink node logs and ensure it started successfully. - Sign in to the Chainlink node's web UI:
- Use your web browser to navigate to http://localhost:6688.
- Login with the following credentials:
- Email:
user@example.com
- Password:
password
- Email:
- Use the Chainlink node web UI to inspect the bridge and jobs that were created when you ran
npm start
. - Use Remix to interact with the deployed Chainlink client smart contract:
- Run
npm run remix
to invoke theremixd
command.remixd
will allow you to use the Remix web IDE to interact with Solidity smart contracts on your local file system. - Use your web browser to navigate to https://remix.ethereum.org and follow the steps to connect Remix to
localhost
. - Use the Remix file explorer to open
the
truffle/contracts/DeliveryLink.sol
contract from this project. - Use the Remix Solidity compiler to compile the
DeliveryLink
contract. - Use the Remix UI to configure Ganache as your Web3 provider.
- Use Ganache to get the address of the deployed
DeliveryLink
contract. - Use Remix to load the deployed instance of
DeliveryLink
. - Use Remix to inspect the
DeliveryLink
contract and view the values of some of its state variables; correlate these with values found on the Chainlink node web UI:getChainlinkOracle
getChainlinkToken
getDeliveryStatusJobId
getTimestampJobId
- Use Remix to inspect the value of the
timestamp
state variable; you should note that the value has not been set. - Use Remix to inspect the definition of the
requestCurrentTimestamp
function on theDeliveryLink
contract and then execute it. - Use the Chainlink node web UI to view the completed job run that was executed as a result of calling the
function on the
DeliveryLink
contract. - Use Remix to inspect the updated value of the
timestamp
state variable. - Use Remix to inspect the value of the
deliveryStatus
state variable; you should note that the value has not been set. - Use Remix to execute the following functions with the provided parameters in order to prepare the
DeliveryLink
contract to exercise the external adapter that was deployed using Docker. The parameter values are test values provided by EasyPost for the purpose of developing with their API:setPackageCarrier
:USPS
setPackageCode
:EZ1000000001
- Use Remix to inspect the definition of the
requestDeliveryStatus
function on theDeliveryLink
contract and then execute it. - Use the Chainlink node web UI to view the completed job run that was executed as a result of calling the
function on the
DeliveryLink
contract. - Use Remix to inspect the updated value of the
deliveryStatus
state variable.
- Run
This project is meant to expose a host of features and capabilities that can be reused for further development.
The chainlink/cl-utils.js
file implements a minimal client for
the Chainlink node REST API as well as some helper functions to assist in
exercising the REST API's capabilities.
This helper function is meant to be used in conjunction with postBridge(bridge)
.
Return value:
{
"name": name,
"url": url
}
This helper function is meant to be used in conjunction with postJob(job)
.
Return value:
{
"initiators": [
{
"type": initiatorType,
"params": {}
}
],
"tasks": []
}
This helper function is meant to be used to add elements to the tasks
array of the object returned by createJob
.
Return value:
{
"type": type,
"params": {}
}
Retrieves the account address of the Chainlink node from the Chainlink node's REST API.
Create a bridge on the Chainlink node using the Chainlink node REST API.
Create a job on the Chainlink node using the Chainlink node REST API.
A key feature of this project is the ease with which external adapters can be deployed and consumed.
To deploy a new external adapter, simply add it as a service to the docker-compose.yml
file
found in this project. The included EasyPost adapter is deployed from source by referring to
the provided Dockerfile.
To see an example of how the features and capabilities of this project can be used to configure a Chainlinked smart
contract to consume an external adapter, please refer to
the provided add-jobs.js
script and the usage steps described above.