Step by step guide to run a Chainlink consumer test with a local chainlink node on Qtum, Rinkeby or Ganache chains.
Ref: https://docs.chain.link/docs/fulfilling-requests/
This project has a number of dependencies, including but not limited to: Node.js, Ganache and Docker.
-
Before using this project, start a Ganache workspace that includes
./truffle/truffle-config.js
from this project and serves on all interfaces (0.0.0.0
). -
Run
npm start
to migrate the Truffle contracts and start a Chainlink node that is connected to Ganache. -
Run
npm run truffle:init-setup
to fund the deployed Chainlink client contract withLINK
, fund your Chainlink node with ETH and give the address of your Chainlink node fulfillment permissions on the deployed oracle contract. -
Run
npm run stop
to shutdown the Chainlink node.
- Migrate contracts with truffle
truffle migrate --network ganache|qtum|rinkeby
- Start Chainlink node
./chainlink/start-cl.sh
- Fund Client contract with LINK
truffle exec ./scripts/request-price.js --network ganache|qtum|rinkeby
- Setting fullfilment and funding Chainlink addres
truffle exec ./scripts/prep-node.js --network ganache|qtum|rinkeby
- Define a Chainlin Job
Use your web browser and the Chainlink node web UI (
localhost:6688
) to add the following job to your Chainlink node
type = "directrequest"
schemaVersion = 1
name = "Get > Uint256"
# Optional External Job ID: Automatically generated if unspecified
# externalJobID = "b1d42cd5-4a3a-4200-b1f7-25a68e48aad8"
contractAddress = "YOUR_ORACLE_CONTRACT_ADDRESS"
maxTaskDuration = "0s"
observationSource = """
decode_log [type="ethabidecodelog"
abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
data="$(jobRun.logData)"
topics="$(jobRun.logTopics)"]
decode_cbor [type="cborparse" data="$(decode_log.data)"]
fetch [type="http" method=GET url="$(decode_cbor.get)"]
parse [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
multiply [type="multiply" input="$(parse)" times=100]
encode_data [type="ethabiencode" abi="(uint256 value)" data="{ \\"value\\": $(multiply) }"]
encode_tx [type="ethabiencode"
abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
]
submit_tx [type="ethtx" to="YOUR_ORACLE_CONTRACT_ADDRESS" data="$(encode_tx)"]
decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""
Replace <YOUR_ORACLE_CONTRACT_ADDRESS>
with your oracle contract address, enclosed in quotation marks. You can find
this value on the configuration page for your Chainlink node.
The credentials to login to the Chainlink node are [email protected]/password
.
- Request ETH price
truffle exec ./scripts/request-price.js --network ganache|qtum|rinkeby
Alternatively, Chainlink node can be ran as a binary by executing following steps (qtum example)
- Start postgres docker container
cd postgres
docker-compose up -d
- Create DB for Qtum Testnet
psql --host=127.0.0.1 -p 5432 --dbname dbchainlink --username=dbuser --password --command="CREATE DATABASE qtumtestnet WITH OWNER dbuser"
- Start chainlink node
- Source environment vars
source qtum-testnet.env
- Start chainlink
source ./chainlink/qtum_testnet.env
cd <location of chainlink node repo>/core
go run main.go local n -p $NODEPWD -a $APIPWD
or
./chainlink local n -p $NODEPWD -a $APIPWD
- Test web Node Operator GUI
Network: Rinkeby (id: 4)
GanacheChainlinkClient: 0xf58e65d6489208eC56d7F4Fc2EF5DDdE7D915d36
LinkToken: 0x86F24969877A4dc4334F7416AF1A6e68D49B8469
Migrations: 0x6AE9F1692C7539cc4E90cA91Ca774d3d98B2b1Ed
Oracle: 0x4E1d35fE640537558547A61F3E016B6b71C8B203
GanacheChainlinkClient: 0x80d2f667e6bBf6Ab2937d1F6697903f858dd9090
LinkToken: 0xE9555c1F9C8C97eeF5D4D9B37f8de07B6B359547
Migrations: 0x21Cad20E7a8b6aFb3268A9c2Ba6575356784dC13
Oracle: 0x7fD9A5E7a38CC396609cf389364e9504F14A5ee6
- frontend
Update App.js
accordingly:
const backendURL = "http://127.0.0.1:3000/demo";
const JANUS="ws://54.193.12.166:23889";
- backend
Update .env
:
JANUS="http://54.193.12.166:23889"
- Chainlink
Update qtum_testnet.env
:
export ETH_URL=ws://54.193.12.166:23889
export DATABASE_URL=postgresql://dbuser:[email protected]:5432/qtumchainlinkdev?sslmode=disable
Backend API expects a qtum node running with a local (funded) wallet for address qUbxboqjBRp96j3La8D1RYkyqx5uQbJPoW
You can subscribe to OracleRequest
event by running the following golang listener
cd utils
go run subscribe_oracle.go qtum 23890
Create a .env
file inside truffle
folder with the infura credentials and seed phrase
MNEMONIC="<seed phrase>"
INFURA_APIKEY="<api key>"
Regular address
hex: "0x78Ad4cB180b93Af91D24f3A62A0346DB15E834F3"
base58: qUZTr7kDgpZDn6uctfv6sHZ4esJPJanCKR
Emergency funding address
hex: "0x4e07e496c5F6b93Ca913c3f20C1838F772c272e7"
base58: qQfyKQPsTLtnzp2Nnr9e5PuByLzXnVQduM
NODE_ENV=production && pm2 start npm --name "qtum-api" -- start