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.
A Python virtual runtime environment that allows smart contracts to execute Python code via Chainlink.
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.
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
Dev - Node v10.19.0 required
cd src2.npm install3.npm run dev
Production
cd srcbash install.shdocker-compose up --build -d, then go to port 80 on your machine to access the API
cd node- Rename
.env.templateto.envand replace the variables defined byCHANGEMEwith 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 Postgresadd on bash start.shand then enter your credentials for the node, then open the link it provides you with to access the node
Instructions - Using the Chainlink node - Node v10.19.0 required
- To interface with any of the custom jobs you will need to add a new bridge in your node called
py-vrewith the URL of your API - To deploy an oracle contract, add your private key
PRIVATE_KEY=and Infura URLINFURA_URL=to.envinnode - To add one of the jobs from
node/jobsto the node, under thejobstab of your node GUI selectNew Job, then copy and paste the job from one of the.tomlfiles. ReplaceCHANGEMEwith 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