@xudean/pado-ao-sdk v0.1.30
pado-ao-sdk
Overview
The pado-ao-sdk helps developers use PADO Network, which provides trustless and confidential computing capabilities. You can learn more about PADO Network.
Quick Start
- Demos
Usage
Installation
Install package by npm
npm install --save @padolabs/pado-ao-sdk
import wasm
Introduce lhe.js
into the HTML file as follows:
<!-- When the JS is introduced, the WASM will automatically load. -->
<script type="text/javascript" src="https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v2/lhe.js"></script>
The WASM version and SDK version have a strict correspondence. The specific relationship is as follows:
Wasm Version | SDK Version | Wasm Link |
---|---|---|
v2 | >=0.2.0 | https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v2/lhe.js |
V1 | 0.0.1<= version<0.2.0 | https://pado-online.s3.ap-northeast-1.amazonaws.com/resources/v1/lhe.js |
If you meet the following error in your browser's console:
_stream_writable.js:57 Uncaught ReferenceError: process is not defined
at node_modules/readable-stream/lib/_stream_writable.js (_stream_writable.js:57:18)
at __require2 (chunk-BYPFWIQ6.js?v=4d6312bd:19:50)
You can refer to project using vite. link
Getting Started
Utils
Generate Key
Generate public-private key pairs for submitting tasks and retrieving task results.
generateKey(param_obj?: any): Promise<KeyInfo>;
- Example
import {Utils} from "@padolabs/pado-ao-sdk";
//The generated key pair will be used for submitTask() and `getTaskResult()
const keyInfo = await new Utils().generateKey();
PadoNetworkContractClient
Import Client
import {PadoNetworkContractClient} from '@padolabs/pado-ao-sdk'
Instantiate Client
The constructor for the PadoNetworkContractClient
.
constructor(chainName: ChainName, wallet: any, storageType: StorageType = StorageType.ARSEEDING);
Parameters
- chainName: The blockchain the client wants to connect to. Learn more about ChainName
- wallet: The wallet that interacts with the blockchain.
- storageType (optional): The storage option the client wants to use for data. The default is
StorageType.ARSEEDING
. Learn more about StorageType
Note:
By default,
StorageType
isARWEAVE
whenchainName
isao
, andARSEEDING
whenchainName
isholesky
orethereum
.
chainName | storageType | Wallet |
---|---|---|
ao | ARWEAVE | window.arweaveWallet |
holesky | ARSEEDING | window.ethereum |
ethereum | ARSEEDING | window.ethereum |
Returns
Example
const chainName = 'holesky';
const storageType = StorageType.ARSEEDING;
//if chainName is holesky or ethereum, wallet should be window.ethereum;
//if chainName is ao, wallet should be window.arweaveWallet;
const wallet = window.ethereum;
const padoNetworkClient = new PadoNetworkContractClient(chainName, wallet, storageType);
Upload Data
Uploading data to the storage chain.
uploadData(data: Uint8Array, dataTag: CommonObject, priceInfo: PriceInfo, encryptionSchema?: EncryptionSchema): Promise<string>;
Parameters
data: The data to be uploaded, which should be of type
Uint8Array
.dataTag: The data's metadata object. Note: Please use an object format, not a string.
priceInfo: The data price symbol. Leran more bout PriceInfo Different
chainName
values correspond to different symbols.chainName symbol minimum price(1 means) ao wAR(the Wrapped AR in AO) 0.000000000001 wAR holesky ETH 1 wei ethereum ETH 1 wei
encryptionSchema(optional): Parameters used by the algorithm. The default is:
{ t: '2', n: '3' }
Returns
dataId
: A unique identifier for the data.
Example
//padoNetworkClient is the object instantiated in the previous section
const data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const dataTag = { 'filename': 'testFileName' };
const priceInfo = { price: '200000000', symbol: 'wAR' };
const dataId = await padoNetworkClient.uploadData(data, dataTag, priceInfo);
Submit Task
Submit a task to the PADO Network. You must pay both the data fee corresponding to the data provider
and the computing fee for the workers
.
submitTask(taskType: string, dataId: string): Promise<string>;
Note:
The public key passed when initialising the client is used to encrypt the task result when submitting the task.
Parameters
taskType: The type of the task; defaults to
0
now.dataId: The
dataId
returned by theuploadData
interface.
Returns
taskId
: The ID of the task.
- Example
const userDataId = 'returned by the uploadData';
const taskId = await padoNetworkClient.submitTask(0, userDataId)
Get Task Result
Get the result of the task.
getTaskResult(taskId: string, timeout?: number): Promise<Uint8Array>;
Note
The task result will be decrypted using the private key in the key pair passed when initialising the client, make sure that the submitTask and getTaskResult interfaces are the same PadoNetworkClient instance!
- Parameters
- taskId: taskId returned by
submitTask
interface - timeout(optional): The timeout in milliseconds for getting the result, if you wait longer than this time a
timeout
exception will be thrown. Default 10000(10 seconds).
- taskId: taskId returned by
- Returns
- Uint8Array: The result of the task in plain text.
- Example
const taskId = 'returned by the getTaskResult';
const timeout = 20000;//milliseconds
//The format of data is Uint8Array, you should handle this data additionally, such as saving it to a file etc.
const data = await padoNetworkClient.getTaskResult(taskId,);
Type And Enum
KeyInfo
type KeyInfo = {
//publick key
pk: string;
//private key
sk: string;
};
ChainName
type ChainName = 'ao' | 'holesky' | 'ethereum';
StorageType
enum StorageType {
ARWEAVE = "arweave",
ARSEEDING = "arseeding"
}
PriceInfo
/**
* Price of data
* if symbol is 'wAR'(chainName is ao), a price of 1 means that the data price is 0.000000000001 wAR.
* if symbol is 'ETH'(chainName is holesky or ethereum),a price of 1 means that the data price is 1wei
* price: The price of data
* symbol: The token symbol of price
*/
interface PriceInfo {
price: string;
symbol: string;
}
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago