1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

changed signature of requestTokens to match py version, adapted readme, removed getInstance()

This commit is contained in:
Sebastian Gerske 2018-09-20 14:19:27 +02:00
parent 82f7b0001c
commit a2c19d7d89
5 changed files with 24 additions and 41 deletions

View File

@ -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')
```

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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() {