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

78 lines
1.8 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 {
aquariusHost,
aquariusPort,
2019-01-23 14:43:41 +01:00
aquariusScheme,
2019-01-23 12:15:16 +01:00
brizoHost,
brizoPort,
2019-01-23 14:43:41 +01:00
brizoScheme,
2019-04-02 13:59:07 +02:00
brizoAddress,
faucetHost,
faucetPort,
faucetScheme,
2019-01-23 14:43:41 +01:00
nodeHost,
nodePort,
nodeScheme,
2019-01-23 12:15:16 +01:00
parityHost,
parityPort,
2019-01-23 14:43:41 +01:00
parityScheme,
2019-01-23 12:15:16 +01:00
secretStoreHost,
secretStorePort,
2019-01-23 14:43:41 +01:00
secretStoreScheme,
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-04-06 17:55:24 +02:00
export async function provideOcean(web3provider: Web3) {
2019-01-23 12:15:16 +01:00
const nodeUri = `${nodeScheme}://${nodeHost}:${nodePort}`
const aquariusUri = `${aquariusScheme}://${aquariusHost}:${aquariusPort}`
const brizoUri = `${brizoScheme}://${brizoHost}:${brizoPort}`
const parityUri = `${parityScheme}://${parityHost}:${parityPort}`
const secretStoreUri = `${secretStoreScheme}://${secretStoreHost}:${secretStorePort}`
const config = {
2019-04-06 17:55:24 +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
parityUri,
secretStoreUri,
verbose
}
2019-04-06 17:55:24 +02:00
const ocean: Ocean = 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 = `${faucetScheme}://${faucetHost}:${faucetPort}/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-04-30 19:19:28 +02:00
Logger.error('requestFromFaucet', error)
}
}