1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/client/src/ocean.ts

56 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Ocean, Logger } from '@oceanprotocol/squid'
2019-04-06 17:55:24 +02:00
import Web3 from 'web3'
2019-01-23 12:15:16 +01:00
import {
aquariusUri,
brizoUri,
2019-04-02 13:59:07 +02:00
brizoAddress,
faucetUri,
nodeUri,
secretStoreUri,
2019-01-23 12:15:16 +01:00
verbose
2019-04-15 21:08:49 +02:00
} from './config'
2019-01-23 12:15:16 +01:00
2019-07-10 10:16:14 +02:00
export async function provideOcean(web3Provider: Web3) {
2019-01-23 12:15:16 +01:00
const config = {
2019-07-10 10:16:14 +02:00
web3Provider,
2019-01-23 12:15:16 +01:00
nodeUri,
aquariusUri,
brizoUri,
2019-04-02 13:59:07 +02:00
brizoAddress,
2019-01-23 12:15:16 +01:00
secretStoreUri,
verbose
}
2019-05-21 12:12:02 +02:00
const ocean: any = await Ocean.getInstance(config)
2019-01-23 12:15:16 +01:00
return { ocean }
}
//
// Faucet
//
export interface FaucetResponse {
success: boolean
message: string
trxHash?: string
}
export async function requestFromFaucet(account: string) {
try {
const url = `${faucetUri}/faucet`
const response = await fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
address: account,
agent: 'commons'
})
})
return response.json()
} catch (error) {
2019-05-14 13:03:48 +02:00
Logger.error('requestFromFaucet', error.message)
}
}