From c18634e131a3262cc38548163f9a8e072f2844c0 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 11 Aug 2024 19:19:24 +0700 Subject: [PATCH] Create oracle.js --- .../pi_network/pi-stablecoin/oracle/oracle.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-stablecoin/oracle/oracle.js diff --git a/blockchain_integration/pi_network/pi-stablecoin/oracle/oracle.js b/blockchain_integration/pi_network/pi-stablecoin/oracle/oracle.js new file mode 100644 index 000000000..69d5bb39b --- /dev/null +++ b/blockchain_integration/pi_network/pi-stablecoin/oracle/oracle.js @@ -0,0 +1,24 @@ +// oracle.js +const Web3 = require('web3'); +const axios = require('axios'); + +class Oracle { + constructor() { + this.web3 = new Web3(new Web3.providers.HttpProvider('https://pi-network-node.com')); + this.oracleAddress = '0x...'; // Oracle service contract address + } + + async getMarketPrice() { + // Call external API to get current market price of PSI + const response = await axios.get('https://api.coingecko.com/api/v3/simple/price?ids=pi-stable-coin&vs_currencies=usd'); + return response.data.pi_stable_coin.usd; + } + + async updatePriceFeed() { + // Update price feed on the blockchain + const price = await this.getMarketPrice(); + this.web3.eth.Contract(this.oracleAddress, 'updatePriceFeed', price); + } +} + +module.exports = Oracle;