mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import { Ocean, Logger } from '@oceanprotocol/squid'
|
|
import Web3 from 'web3'
|
|
|
|
import {
|
|
aquariusHost,
|
|
aquariusPort,
|
|
aquariusScheme,
|
|
brizoHost,
|
|
brizoPort,
|
|
brizoScheme,
|
|
brizoAddress,
|
|
faucetHost,
|
|
faucetPort,
|
|
faucetScheme,
|
|
nodeHost,
|
|
nodePort,
|
|
nodeScheme,
|
|
parityHost,
|
|
parityPort,
|
|
parityScheme,
|
|
secretStoreHost,
|
|
secretStorePort,
|
|
secretStoreScheme,
|
|
verbose
|
|
} from './config'
|
|
|
|
export async function provideOcean(web3provider: Web3) {
|
|
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 = {
|
|
web3provider,
|
|
nodeUri,
|
|
aquariusUri,
|
|
brizoUri,
|
|
brizoAddress,
|
|
parityUri,
|
|
secretStoreUri,
|
|
verbose
|
|
}
|
|
|
|
const ocean: Ocean = await Ocean.getInstance(config)
|
|
|
|
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) {
|
|
Logger.error('requestFromFaucet', error.message)
|
|
}
|
|
}
|