Chainlink VRE Adapter
WARNING: DO NOT RUN CODE THAT YOU DO NOT UNDERSTAND. BE CAREFUL WHEN GIVING THIS SCRIPT ACCESS TO YOUR PRIVATE KEY. I AM NOT RESPONSIBLE FOR ANY FUNDS YOU MAY LOSE.
Chainlink.
A Python virtual runtime environment that allows smart contracts to execute Python code viaDescription
This repository contains the files needed to start the Python code isolated execution API, as well as the scripts required to create your own Chainlink node that can fetch the off chain data from the API and return it to the contract on chain.
A demo of the API can be found here. It should be noted that the host machine has very limited RAM as this is only a test environment, and is likely to fail on rapid calls or while fulfilling a request. The addresses of the contracts deployed to the Rinkeby network can be found in node/address.json
.
Requirements
Using the node in a smart contract
Chainlink.Request memory req = buildChainlinkRequest(_jobId, address(this), this.fulfillResult.selector);
req.add("version", "3.9.9"); // Valid version include "3.8.12", "3.9.9", "3.10.0"
req.add("code", "import requests;import json;print(json.dumps({ 'data': 3 }))"); // Your output will be read from the 'data' field in the output JSON - make sure you choose the correct jobId for the type of data you wish to receive in return
req.add("packages", "requests,"); // A comma seperated list of dependencies - the more dependencies you have the longer it will take to run - the API WILL time out if it takes longer than 30 seconds
sendChainlinkRequestTo(_oracle, req, ORACLE_PAYMENT);
For a real example look at node/contracts/Test.sol
Instructions - Running the API
Dev - Node v10.19.0 required
cd src
2.npm install
3.npm run dev
Production
cd src
bash install.sh
docker-compose up --build -d
, then go to port 80 on your machine to access the API
Instructions - Running the Chainlink node
cd node
- Rename
.env.template
to.env
and replace the variables defined byCHANGEME
with their respective parameters. You will need access to an Ethereum JSON-RPC API which you can get using Infura (MAKE SURE YOU USE THE WEBSOCKET VERSIONwss://...
), and you will need a database URI which you can get from Heroku, creating a new app, and installing theHeroku Postgres
add on bash start.sh
and then enter your credentials for the node, then open the link it provides you with to access the node
Node v10.19.0 required
Instructions - Using the Chainlink node -- To interface with any of the custom jobs you will need to add a new bridge in your node called
py-vre
with the URL of your API - To deploy an oracle contract, add your private key
PRIVATE_KEY=
and Infura URLINFURA_URL=
to.env
innode
- To add one of the jobs from
node/jobs
to the node, under thejobs
tab of your node GUI selectNew Job
, then copy and paste the job from one of the.toml
files. ReplaceCHANGEME
with the address of your deployed oracle contract - It should be noted that each job is suitable for a different return type (bool, bytes32, int256, uint256) - use the appropriate job for the appropriate type of data you wish for your contract to receive