Data Sharing
Overview
This guide introduces how to use the BAVO NETWORK SDK with examples to help you get started.
Preparations
Node.js: Version 18 or above
MetaMask: Required if using Ethereum or Holesky chains
Ensure you have enough ETH in your wallet to cover gas and computation fees.
EverPay: Ensure you have enough ETH in EverPay to cover storage fees (see SDK documentation for more details).
ArConnect: Required if using the AO chain
Ensure you have enough wAR (Wrapped AR) in your wallet.
How to Run the Demo
Clone the repository:
bashCopy codegit clone https://github.com/pado-labs/bavo-network-sdk.git cd pado-network-sdk cd demo
Install the packages:
bashCopy codenpm install
Usage
Installation
Install the BAVO SDK via npm:
bashCopy codenpm install --save @bavolabs/bavo-network-sdk
Initialize Client
For AO Chain:
Ensure ArConnect is installed in Chrome and that you have enough AR.
javascriptCopy codeconst wallet = window.arweaveWallet;
const bavoNetworkClient = new BavoNetworkContractClient('ao', wallet, 'arweave');
For Ethereum or Holesky Chains:
Ensure MetaMask is installed in Chrome and you have enough ETH for gas and computation fees, as well as ETH in EverPay for storage.
javascriptCopy codeconst wallet = window.ethereum;
const bavoNetworkClient = new BavoNetworkContractClient('holesky', wallet, 'arseeding');
Data Provider
Upload Data
Prepare the data in Uint8Array format:
javascriptCopy codeconst data = new Uint8Array(fileContent);
Tag the data (e.g., filename and suffix):
javascriptCopy codeconst dataTag = {'name': 'test', 'suffix': 'txt'};
Set the price for the data:
For Holesky or Ethereum:
javascriptCopy codeconst priceInfo = { price: 1_000_000_000_000, // 0.0000001 ETH symbol: 'ETH' };
For AO (using wAR):
javascriptCopy codeconst priceInfo = { price: '200000000', // 0.0002 wAR symbol: 'wAR' };
Define data permissions (optional):
javascriptCopy codeconst dataPermissions = [];
Set the encryption schema (optional):
javascriptCopy codeconst schema = { t: 2, // Minimum number of nodes n: 3 // Total number of nodes };
Upload the data:
javascriptCopy codeconst dataId = await bavoNetworkClient.uploadData(data, dataTag, priceInfo, dataPermissions, schema);
If successful, you will receive a
dataId
to query your uploaded data.
Retrieve Balance and Withdraw Tokens
Data providers earn token rewards when their data is purchased. You can check and withdraw the balance as follows:
Get balance:
javascriptCopy codeconst balance = await bavoNetworkClient.getBalance(address, 'ETH'); console.log(balance.locked.toString()); console.log(balance.free.toString());
Withdraw tokens:
javascriptCopy codeconst transaction = await bavoNetworkClient.withdrawToken(metamaskAddress, 'ETH', balance.free); console.log(transaction);
Data User
Generate Key Pair
You must generate a public-private key pair for encryption and decryption:
javascriptCopy codeimport { Utils } from "@bavolabs/bavo-network-sdk";
const keyInfo = await new Utils().generateKey();
Submit Task
To submit a task, you need the dataId
provided by the Data Provider.
javascriptCopy codeconst taskId = await bavoNetworkClient.submitTask(TaskType.DATA_SHARING, userDataId, keyInfo.pk);
This will return a taskId
to use when retrieving the result.
Get Task Result
Retrieve the task result:
javascriptCopy codeconst data = await bavoNetworkClient.getTaskResult(taskId, keyInfo.sk);
If successful, you will receive the data in Uint8Array
format for further processing.
Conclusion
Using the BAVO NETWORK SDK, developers can easily interact with the network to upload data, submit tasks, retrieve results, and manage balances.
Last updated