1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

Issue-1042: Add content on creating ocean.js configuration

This commit is contained in:
Akshay 2022-07-09 13:00:07 +02:00
parent 7082901bd2
commit 98d53c8f9e
3 changed files with 157 additions and 2 deletions

View File

@ -21,6 +21,7 @@
* [Aquarius REST API](api-references/aquarius-rest-api.md) * [Aquarius REST API](api-references/aquarius-rest-api.md)
* [Provider REST API](api-references/provider-rest-api.md) * [Provider REST API](api-references/provider-rest-api.md)
* [Building with ocean](building-with-ocean/README.md) * [Building with ocean](building-with-ocean/README.md)
* [Obtaining API key](building-with-ocean/obtaining-api-key.md)
* [Using Ocean libraries](building-with-ocean/using-ocean-libraries/README.md) * [Using Ocean libraries](building-with-ocean/using-ocean-libraries/README.md)
* [Configuration](building-with-ocean/using-ocean-libraries/configuration.md) * [Configuration](building-with-ocean/using-ocean-libraries/configuration.md)
* [Publish assets using hosting services](building-with-ocean/asset-hosting.md) * [Publish assets using hosting services](building-with-ocean/asset-hosting.md)

View File

@ -1,12 +1,159 @@
# Configuring Ocean libraries # Configuration
### Obtaining API key
See this [guide](../obtaining-api-key.md) on getting an API key to interact with EVM compatible networks.
#### Create a directory
```
mkdir my-ocean-project
cd my-ocean-project
```
### Create a `.env` file ### Create a `.env` file
{% tabs %}
{% tab title="Mainnet" %}
{% code title=".env" %}
``` ```
# Mandatory environment variables
OCEAN_NETWORK=mainnet
NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.mainnet.oceanprotocol.com
```
{% endcode %}
{% endtab %}
{% tab title="Polygon" %}
{% code title=".env" %}
```
# Mandatory environment variables
OCEAN_NETWORK=polygon
NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.polygon.oceanprotocol.com
```
{% endcode %}
{% endtab %}
{% tab title="Local (using Barge)" %}
{% code title=".env" %}
```
# Mandatory environment variables
NETWORK_URL=http://172.15.0.3:8545/ NETWORK_URL=http://172.15.0.3:8545/
AQUARIUS_URL=http://172.15.0.5:5000 AQUARIUS_URL=http://172.15.0.5:5000
PROVIDER_URL=http://172.15.0.4:8030 PROVIDER_URL=http://172.15.0.4:8030
MNEMONIC=<secret>
# Replace PRIVATE_KEY if needed
PRIVATE_KEY=0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58
OCEAN_NETWORK=development OCEAN_NETWORK=development
``` ```
{% endcode %}
{% endtab %}
{% endtabs %}
#### Setup dependencies
{% tabs %}
{% tab title="ocean.js" %}
```bash
npm init
npm install @oceanprotocol/lib@latest dotenv web3 @truffle/hdwallet-provider
```
{% endtab %}
{% tab title="ocean.py" %}
```bash
python3 -m venv venv
source venv/bin/activate
pip3 install wheel
# Install Ocean library. Allow pre-releases to get the latest v4 version.
pip3 install ocean-lib
```
{% endtab %}
{% endtabs %}
#### Create a configuration file
{% tabs %}
{% tab title="ocean.js" %}
{% code title="config.js" %}
```javascript
// Import dependencies
require('dotenv').config();
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const { homedir } = require('os');
const { ConfigHelper } = require('@oceanprotocol/lib');
// Get configuration for the given network
let oceanConfig = new ConfigHelper().getConfig(process.env.OCEAN_NETWORK);
// If using local development environment, read the addresses from local file.
// The local deployment address file can be generated using barge.
if (process.env.OCEAN_NETWORK === 'development') {
const addressData = JSON.parse(
fs.readFileSync(
process.env.ADDRESS_FILE
|| `${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
'utf8'
)
);
const addresses = addressData[process.env.OCEAN_NETWORK];
oceanConfig = {
...oceanConfig,
oceanTokenAddress: addresses.Ocean,
poolTemplateAddress: addresses.poolTemplate,
fixedRateExchangeAddress: addresses.FixedPrice,
dispenserAddress: addresses.Dispenser,
erc721FactoryAddress: addresses.ERC721Factory,
sideStakingAddress: addresses.Staking,
opfCommunityFeeCollector: addresses.OPFCommunityFeeCollector
};
}
oceanConfig = {
...oceanConfig,
nodeUri: process.env.NETWORK_URL,
// Set optional properties - Provider URL and Aquarius URL
metadataCacheUri: process.env.AQUARIUS_URL || oceanConfig.metadataCacheUri,
providerUri: process.env.PROVIDER_URL || oceanConfig.providerUri
};
const web3Provider = new HDWalletProvider(
process.env.PRIVATE_KEY,
oceanConfig.nodeUri
);
module.exports = {
web3Provider,
oceanConfig
};
```
{% endcode %}
{% endtab %}
{% tab title="ocean.py" %}
{% code title="config.py" %}
```python
```
{% endcode %}
{% endtab %}
{% endtabs %}

View File

@ -0,0 +1,7 @@
# Obtaining API key
Choose any api provider of your choice. Some of the commonly used are:
* [Infura](https://infura.io/)
* [Alchemy](https://www.alchemy.com/)
* [Moralis](https://moralis.io/)