Skip to content

Commit

Permalink
Create index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent b2219d8 commit 120ba34
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions projects/DAPIO/client/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Web3 from 'web3';
import { Dapio } from './Dapio';

const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/v3/YOUR_PROJECT_ID'));

const dapioContract = new web3.eth.Contract(Dapio.abi, '0x...DapioContractAddress...');

export async function createDataFeed(dataFeedName, dataFeedDescription) {
const txCount = await web3.eth.getTransactionCount();
const tx = {
from: '0x...YourEthereumAddress...',
to: dapioContract.address,
value: '0',
gas: '200000',
gasPrice: '20',
nonce: txCount,
data: dapioContract.methods.createDataFeed(dataFeedName, dataFeedDescription).encodeABI(),
};

const signedTx = await web3.eth.accounts.signTransaction(tx, '0x...YourEthereumPrivateKey...');
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);

return receipt;
}

export async function trainAiModel(aiModelType, dataFeedAddress) {
const txCount = await web3.eth.getTransactionCount();
const tx = {
from: '0x...YourEthereumAddress...',
to: dapioContract.address,
value: '0',
gas: '200000',
gasPrice: '20',
nonce: txCount,
data: dapioContract.methods.trainAiModel(aiModelType, dataFeedAddress).encodeABI(),
};

const signedTx = await web3.eth.accounts.signTransaction(tx, '0x...YourEthereumPrivateKey...');
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);

return receipt;
}

export async function updateDataFeed(dataFeedAddress, dataFeedName, dataFeedDescription) {
const txCount = await web3.eth.getTransactionCount();
const tx = {
from: '0x...YourEthereumAddress...',
to: dapioContract.address,
value: '0',
gas: '200000',
gasPrice: '20',
nonce: txCount,
data: dapioContract.methods.updateDataFeed(dataFeedAddress, dataFeedName, dataFeedDescription).encodeABI(),
};

const signedTx = await web3.eth.accounts.signTransaction(tx, '0x...YourEthereumPrivateKey...');
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction);

return receipt;
}

export async function delete

0 comments on commit 120ba34

Please sign in to comment.