diff --git a/README.md b/README.md index bfa2001..aeccc90 100644 --- a/README.md +++ b/README.md @@ -36,20 +36,20 @@ Start by adding the package to your dependencies: npm i @oceanprotocol/squid ``` -The package exposes `OceanAgent` and `OceanKeeper` which you can import in your code like so: +The package exposes `OceanAgent` and `Ocean` which you can import in your code like so: ```js // ES6 -import { OceanAgent, OceanKeeper } from '@oceanprotocol/squid' +import { OceanAgent, Ocean } from '@oceanprotocol/squid' // ES2015 -const { OceanAgent, OceanKeeper } = require('@oceanprotocol/squid') +const { OceanAgent, Ocean } = require('@oceanprotocol/squid') ``` You can then connect to a running [Keeper](https://github.com/oceanprotocol/keeper-contracts) & [Provider](https://github.com/oceanprotocol/provider) instance, e.g.: ```js -const oceanKeeper = new OceanKeeper('http://localhost:8545', 'development') +const ocean = await new Ocean({uri: 'http://localhost:8545', network: 'development'}) const oceanAgent = new OceanAgent('http://localhost:5000/api/v1/provider') ``` diff --git a/src/keeper/auth.js b/src/keeper/auth.js index 5b63ee1..3594e87 100644 --- a/src/keeper/auth.js +++ b/src/keeper/auth.js @@ -5,14 +5,10 @@ export default class OceanAuth extends KeeperBase { constructor(web3, network) { super(web3, network) - const instance = this - - return { - async getInstance() { - instance.contract = await ContractLoader.load('OceanAuth', instance._network, instance._web3) - return instance - } - } + return (async () => { + this.contract = await ContractLoader.load('OceanAuth', this._network, this._web3) + return this + })() } cancelAccessRequest(orderId, senderAddress) { diff --git a/src/keeper/market.js b/src/keeper/market.js index 9dbc59b..2b1b364 100644 --- a/src/keeper/market.js +++ b/src/keeper/market.js @@ -7,15 +7,10 @@ export default class OceanMarket extends KeeperBase { constructor(web3, network) { super(web3, network) - const instance = this - - return { - async getInstance() { - instance.contract = await ContractLoader.load('OceanMarket', instance._network, instance._web3) - - return instance - } - } + return (async () => { + this.contract = await ContractLoader.load('OceanMarket', this._network, this._web3) + return this + })() } // call functions (costs no gas) @@ -33,8 +28,8 @@ export default class OceanMarket extends KeeperBase { } // Transactions with gas cost - requestTokens(senderAddress, numTokens) { - return this.contract.requestTokens(numTokens, { from: senderAddress }) + requestTokens(amount, address) { + return this.contract.requestTokens(amount, { from: address }) } async registerAsset(name, description, price, publisherAddress) { diff --git a/src/keeper/token.js b/src/keeper/token.js index d7368bf..7ea6893 100644 --- a/src/keeper/token.js +++ b/src/keeper/token.js @@ -6,15 +6,11 @@ export default class OceanToken extends KeeperBase { constructor(web3, network) { super(web3, network) - const instance = this + return (async () => { + this.contract = await ContractLoader.load('OceanToken', this._network, this._web3) - return { - async getInstance() { - instance.contract = await ContractLoader.load('OceanToken', instance._network, instance._web3) - - return instance - } - } + return this + })() } getTokenBalance(accountAddress) { diff --git a/src/ocean.js b/src/ocean.js index f23f71b..91cb700 100644 --- a/src/ocean.js +++ b/src/ocean.js @@ -16,17 +16,13 @@ export default class Ocean { this.helper = new Web3Helper(this._web3) - const instance = this + return (async () => { + this.market = await new OceanMarket(this._web3, this._network) + this.auth = await new OceanAuth(this._web3, this._network) + this.token = await new OceanToken(this._web3, this._network) - return { - async getInstance() { - instance.market = await new OceanMarket(instance._web3, instance._network).getInstance() - instance.auth = await new OceanAuth(instance._web3, instance._network).getInstance() - instance.token = await new OceanToken(instance._web3, instance._network).getInstance() - - return instance - } - } + return this + })() } async getAccounts() {