Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add usage examples #54

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A typescript library helping to navigate the OCEAN. It enables configurable auto
- [Compute Services](#compute-services)
- [Datatoken](#datatoken)
- [Service name and description](#service-name-and-description)
- [Adding services via the AssetBuilder](#adding-services-via-the-assetbuilder)
- [Asset Owner](#asset-owner)
- [Optional Configurations](#optional-configurations)
- [Credentials](#credentials)
Expand All @@ -29,6 +30,10 @@ A typescript library helping to navigate the OCEAN. It enables configurable auto
- [API Documentation](#api-documentation)
- [License](#license)

> [!NOTE]
> You can find full TypeScript examples in the [nautilus-examples](https://github.com/deltaDAO/nautilus-examples) repository.


## Configuring a new Nautilus instance

Setting up a new `Nautilus` instance to perform automated tasks, like publish & consume, is rather simple.
Expand Down
67 changes: 67 additions & 0 deletions docs/docs/Examples/Access.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
id: 'access'
title: 'Access Services(Download)'
sidebar_label: 'Access Services(Download)'
sidebar_position: 1
custom_edit_url: null
---

# Access(Download) of data/algorithm service offerings

The following example shows how to retrieve a download-url for a dataset serviced offering which was published for access(download). The same process is also possible to access algorithms which have been published as access assets.

```ts
import * as dotenv from 'dotenv'
import { LogLevel, Nautilus } from '@deltadao/nautilus'
import { Wallet, providers } from 'ethers'
dotenv.config()

const networkConfig = {
chainId: 80001,
network: 'mumbai',
metadataCacheUri: 'https://v4.aquarius.oceanprotocol.com',
nodeUri: 'https://rpc-mumbai.maticvigil.com',
providerUri: 'https://v4.provider.oceanprotocol.com',
subgraphUri: 'https://v4.subgraph.mumbai.oceanprotocol.com',
explorerUri: 'https://mumbai.polygonscan.com',
oceanTokenAddress: '0xd8992Ed72C445c35Cb4A2be468568Ed1079357c8',
oceanTokenSymbol: 'OCEAN',
fixedRateExchangeAddress: '0x25e1926E3d57eC0651e89C654AB0FA182C6D5CF7',
dispenserAddress: '0x21bc18b92F7551e715B490E2C2875E8532317F8d',
startBlock: 26354458,
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 1,
transactionPollingTimeout: 750,
gasFeeMultiplier: 1.1,
nftFactoryAddress: '0x7d46d74023507D30ccc2d3868129fbE4e400e40B',
opfCommunityFeeCollector: '0xd8839c98ca8CE07dDa4e460a71B634A4A82f8BD6',
veAllocate: '0x3fa1d5AC45ab1Ff9CFAe227c5583Ec0484b54Ef9',
veOCEAN: '0x061955B6980A34fce74b235f90DBe20d76f087b1',
veDelegation: '0x96E3aE4247a01C3d40a261df1F8ead70E32E7C0c',
veFeeDistributor: '0x35F1e6765750E874EB9d0675393A1A394A4749b4',
veDelegationProxy: '0x51B1b14b8bfb43a2fB0b49843787Ca440200F6b7',
DFRewards: '0x4259c164eedA7483dda2b4b622D761A88674D31f',
DFStrategyV1: '0x1be9C72500B41c286C797D4FE727747Ae9C4E195',
veFeeEstimate: '0xCFeF55c6ae4d250586e293f29832967a04A9087d'
}

const privateKey = process.env.PRIVATE_KEY as string
const provider = new providers.JsonRpcProvider(networkConfig.nodeUri)
const wallet = new Wallet(privateKey, provider)

async function main() {
Nautilus.setLogLevel(LogLevel.Verbose) // optional to show more nautilus internal logs
const nautilus = await Nautilus.create(wallet, networkConfig)

// GET DOWNLOAD URL
await access(nautilus)
}

async function access(nautilus: Nautilus) {
const accessUrl = await nautilus.access({
assetDid:
'did:op:7c2024f5f09a5837c3ce060531d59348fee296dc643bcb3e6dc89860672c3db8'
})
console.log('Download URL: ', accessUrl)
}
```
111 changes: 111 additions & 0 deletions docs/docs/Examples/Compute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
id: 'compute'
title: 'Compute'
sidebar_label: 'Compute'
sidebar_position: 2
custom_edit_url: null
---

# Computation

## Start a compute job and get the current status

The following example shows how to start a compute job given a dataset and an algorithm. Afterwards the status of the job is retrieved using the `jobId`.

```ts
import * as dotenv from 'dotenv'
import { LogLevel, Nautilus } from '@deltadao/nautilus'
import { Wallet, providers } from 'ethers'
dotenv.config()

const networkConfig = {
chainId: 80001,
network: 'mumbai',
metadataCacheUri: 'https://v4.aquarius.oceanprotocol.com',
nodeUri: 'https://rpc-mumbai.maticvigil.com',
providerUri: 'https://v4.provider.oceanprotocol.com',
subgraphUri: 'https://v4.subgraph.mumbai.oceanprotocol.com',
explorerUri: 'https://mumbai.polygonscan.com',
oceanTokenAddress: '0xd8992Ed72C445c35Cb4A2be468568Ed1079357c8',
oceanTokenSymbol: 'OCEAN',
fixedRateExchangeAddress: '0x25e1926E3d57eC0651e89C654AB0FA182C6D5CF7',
dispenserAddress: '0x21bc18b92F7551e715B490E2C2875E8532317F8d',
startBlock: 26354458,
transactionBlockTimeout: 50,
transactionConfirmationBlocks: 1,
transactionPollingTimeout: 750,
gasFeeMultiplier: 1.1,
nftFactoryAddress: '0x7d46d74023507D30ccc2d3868129fbE4e400e40B',
opfCommunityFeeCollector: '0xd8839c98ca8CE07dDa4e460a71B634A4A82f8BD6',
veAllocate: '0x3fa1d5AC45ab1Ff9CFAe227c5583Ec0484b54Ef9',
veOCEAN: '0x061955B6980A34fce74b235f90DBe20d76f087b1',
veDelegation: '0x96E3aE4247a01C3d40a261df1F8ead70E32E7C0c',
veFeeDistributor: '0x35F1e6765750E874EB9d0675393A1A394A4749b4',
veDelegationProxy: '0x51B1b14b8bfb43a2fB0b49843787Ca440200F6b7',
DFRewards: '0x4259c164eedA7483dda2b4b622D761A88674D31f',
DFStrategyV1: '0x1be9C72500B41c286C797D4FE727747Ae9C4E195',
veFeeEstimate: '0xCFeF55c6ae4d250586e293f29832967a04A9087d'
}

const privateKey = process.env.PRIVATE_KEY as string
const provider = new providers.JsonRpcProvider(networkConfig.nodeUri)
const wallet = new Wallet(privateKey, provider)

async function main() {
Nautilus.setLogLevel(LogLevel.Verbose) // optional to show more nautilus internal logs
const nautilus = await Nautilus.create(wallet, networkConfig)

// COMPUTE FLOW
const computeJob = await compute(nautilus)
await getComputeStatus(nautilus, computeJob.jobId)
}

async function compute(nautilus: Nautilus) {
console.log(`Your address is ${await wallet.getAddress()}`)

const dataset = {
did: 'did:op:1c96f7ff7e98f9a3fe271a6e59db4b28b9730c955f6ddf3c7bec5632ef90986a' // any 'compute' dataset
}

const algorithm = {
did: 'did:op:b39190deee2d92b74a02fbb01381599ae03b6630ceec362339a136c8fe1e413e' // any 'compute' algorithm allowed to be run on the given dataset (needs to be whitelisted on the dataset)
}

const computeConfig = {
dataset,
algorithm
}

const computeJob = await nautilus.compute(computeConfig)
console.log('COMPUTE JOB: ', computeJob)
return Array.isArray(computeJob) ? computeJob[0] : computeJob
}

async function getComputeStatus(nautilus: Nautilus, jobId: string) {
const computeJobStatus = await nautilus.getComputeStatus({
jobId,
providerUri: networkConfig.providerUri
})
console.log('Compute Job Status: ', computeJobStatus)
}
```

## Retrieve compute results

```ts
async function main() {
Nautilus.setLogLevel(LogLevel.Verbose) // optional to show more nautilus internal logs
const nautilus = await Nautilus.create(wallet, networkConfig)

// RETRIEVE RESULTS
await retrieveComputeResult(nautilus, computeJob.jobId)
}

async function retrieveComputeResult(nautilus: Nautilus, jobId: string) {
const computeResult = await nautilus.getComputeResult({
jobId,
providerUri: networkConfig.providerUri
})
console.log('Compute Result URL: ', computeResult)
}
```
Loading