mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
28 lines
839 B
TypeScript
28 lines
839 B
TypeScript
import { Ocean, Config, Account, Logger } from '@oceanprotocol/squid'
|
|
import Balance from '@oceanprotocol/squid/dist/node/models/Balance'
|
|
import Web3 from 'web3'
|
|
|
|
export async function connectOcean(
|
|
web3: Web3,
|
|
config: Config
|
|
): Promise<{
|
|
ocean: Ocean
|
|
account: Account
|
|
accountId: string
|
|
balance: Balance
|
|
}> {
|
|
Logger.debug('Connecting to Ocean...')
|
|
const ocean = await Ocean.getInstance({
|
|
web3Provider: web3.currentProvider,
|
|
...config
|
|
})
|
|
Logger.debug('Ocean instance ready.')
|
|
// TODO : ocean was not connected and yet i got here and account was undefined so getId() threw an unmanaged error
|
|
const oceanAccounts = await ocean.accounts.list()
|
|
const account = oceanAccounts[0]
|
|
const accountId = account.getId()
|
|
const balance = await account.getBalance()
|
|
|
|
return { ocean, account, accountId, balance }
|
|
}
|