Skip to content

Commit

Permalink
Create oracle.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 11, 2024
1 parent 2dd5297 commit c18634e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions blockchain_integration/pi_network/pi-stablecoin/oracle/oracle.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c18634e

Please sign in to comment.