2019-04-15 14:20:37 +02:00
|
|
|
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 {
|
2019-06-12 03:14:24 +02:00
|
|
|
aquariusUri,
|
|
|
|
brizoUri,
|
2019-04-02 13:59:07 +02:00
|
|
|
brizoAddress,
|
2019-06-12 03:14:24 +02:00
|
|
|
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 }
|
|
|
|
}
|
2019-04-15 14:20:37 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Faucet
|
|
|
|
//
|
|
|
|
export interface FaucetResponse {
|
|
|
|
success: boolean
|
|
|
|
message: string
|
|
|
|
trxHash?: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function requestFromFaucet(account: string) {
|
|
|
|
try {
|
2019-06-12 03:14:24 +02:00
|
|
|
const url = `${faucetUri}/faucet`
|
2019-04-15 14:20:37 +02:00
|
|
|
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)
|
2019-04-15 14:20:37 +02:00
|
|
|
}
|
|
|
|
}
|