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
LINKtoken, 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
LINKtokens. - Set fulfillment permission to
truefor 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 ito install dependencies. - Update the
API_KEYkey value in theadapters/easypost/.envfile to reflect the value of your EasyPost API key. - Create a new workspace in Ganache:
- On the
Workspacetab, addtruffle/truffle-config.jsfrom this project. - On the server tab, select the
0.0.0.0 - All Interfaceshostname. - Save the workspace.
- Run
npm startto perform the steps described above. - Run
npm run chainlink:logsto 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:
[email protected] - 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 remixto invoke theremixdcommand.remixdwill 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.solcontract from this project. - Use the Remix Solidity compiler to compile the
DeliveryLinkcontract. - Use the Remix UI to configure Ganache as your Web3 provider.
- Use Ganache to get the address of the deployed
DeliveryLinkcontract. - Use Remix to load the deployed instance of
DeliveryLink. - Use Remix to inspect the
DeliveryLinkcontract and view the values of some of its state variables; correlate these with values found on the Chainlink node web UI:getChainlinkOraclegetChainlinkTokengetDeliveryStatusJobIdgetTimestampJobId
- Use Remix to inspect the value of the
timestampstate variable; you should note that the value has not been set. - Use Remix to inspect the definition of the
requestCurrentTimestampfunction on theDeliveryLinkcontract 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
DeliveryLinkcontract. - Use Remix to inspect the updated value of the
timestampstate variable. - Use Remix to inspect the value of the
deliveryStatusstate 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
DeliveryLinkcontract 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:USPSsetPackageCode:EZ1000000001
- Use Remix to inspect the definition of the
requestDeliveryStatusfunction on theDeliveryLinkcontract 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
DeliveryLinkcontract. - Use Remix to inspect the updated value of the
deliveryStatusstate 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.