LogoLogo
WebsitePredictoorData ChallengesData FarmingOcean.pyOcean.js
  • 👋Ocean docs
  • 🌊Discover Ocean
    • Why Ocean?
    • What is Ocean?
    • What can you do with Ocean?
    • OCEAN: The Ocean token
    • Networks
    • Network Bridges
    • FAQ
    • Glossary
  • 📚User Guides
    • Basic concepts
    • Using Wallets
      • Set Up MetaMask
    • Host Assets
      • Uploader
      • Arweave
      • AWS
      • Azure Cloud
      • Google Storage
      • Github
    • Liquidity Pools [deprecated]
  • 💻Developers
    • Architecture Overview
    • Ocean Nodes
      • Node Architecture
    • Contracts
      • Data NFTs
      • Datatokens
      • Data NFTs and Datatokens
      • Datatoken Templates
      • Roles
      • Pricing Schemas
      • Fees
    • Publish Flow Overview
    • Revenue
    • Fractional Ownership
    • Community Monetization
    • Metadata
    • Identifiers (DIDs)
    • New DDO Specification
    • Obsolete DDO Specification
    • Storage Specifications
    • Fine-Grained Permissions
    • Retrieve datatoken/data NFT addresses & Chain ID
    • Get API Keys for Blockchain Access
    • Barge
      • Local Setup
    • Ocean.js
      • Configuration
      • Creating a data NFT
      • Publish
      • Mint Datatokens
      • Update Metadata
      • Asset Visibility
      • Consume Asset
      • Run C2D Jobs
    • Ocean CLI
      • Install
      • Publish
      • Edit
      • Consume
      • Run C2D Jobs
    • DDO.js
      • Instantiate a DDO
      • DDO Fields interactions
      • Validate
      • Edit DDO Fields
    • Compute to data
    • Compute to data
    • Uploader
      • Uploader.js
      • Uploader UI
      • Uploader UI to Market
    • VSCode Extension
    • Old Infrastructure
      • Aquarius
        • Asset Requests
        • Chain Requests
        • Other Requests
      • Provider
        • General Endpoints
        • Encryption / Decryption
        • Compute Endpoints
        • Authentication Endpoints
      • Subgraph
        • Get data NFTs
        • Get data NFT information
        • Get datatokens
        • Get datatoken information
        • Get datatoken buyers
        • Get fixed-rate exchanges
        • Get veOCEAN stats
    • Developer FAQ
  • 📊Data Scientists
    • Ocean.py
      • Install
      • Local Setup
      • Remote Setup
      • Publish Flow
      • Consume Flow
      • Compute Flow
      • Ocean Instance Tech Details
      • Ocean Assets Tech Details
      • Ocean Compute Tech Details
      • Datatoken Interface Tech Details
    • Join a Data Challenge
    • Sponsor a Data Challenge
    • Data Value-Creation Loop
    • What data is valuable?
  • 👀Predictoor
  • 💰Data Farming
    • Predictoor DF
      • Guide to Predictoor DF
    • FAQ
  • 🔨Infrastructure
    • Set Up a Server
    • Deploy Aquarius
    • Deploy Provider
    • Deploy Ocean Subgraph
    • Deploy C2D
    • For C2D, Set Up Private Docker Registry
  • 🤝Contribute
    • Collaborators
    • Contributor Code of Conduct
    • Legal Requirements
Powered by GitBook
LogoLogo

Ocean Protocol

  • Website
  • Blog
  • Data Challenges

Community

  • Twitter
  • Discord
  • Telegram
  • Instagram

Resources

  • Whitepaper
  • GitHub
  • Docs

Copyright 2024 Ocean Protocol Foundation Ltd.

On this page
  • Create a directory
  • Create a .env file
  • Setup dependencies
  • Installation & Usage
  • Create a configuration file

Was this helpful?

Edit on GitHub
Export as PDF
  1. Developers
  2. Ocean.js

Configuration

Last updated 1 year ago

Was this helpful?

For obtaining the API keys for blockchain access and setting the correct environment variables, please consult first and proceed with the next steps.

Create a directory

Let's start with creating a working directory where we store the environment variable file, configuration files, and the scripts.

mkdir my-ocean-project
cd my-ocean-project

Create a .env file

In the working directory create a .env file. The content of this file will store the values for the following variables:

Variable name
Description
Required

OCEAN_NETWORK

Name of the network where the Ocean Protocol's smart contracts are deployed.

Yes

OCEAN_NETWORK_URL

The URL of the Ethereum node (along with API key for non-local networks)**

Yes

PRIVATE_KEY

The private key of the account which you want to use. A private key is made up of 64 hex characters. Make sure you have sufficient balance to pay for the transaction fees.

Yes

AQUARIUS_URL

The URL of the Aquarius. This value is needed when reading an asset from off-chain store.

No

PROVIDER_URL

The URL of the Provider. This value is needed when publishing a new asset or update an existing asset.

No

Treat this file as a secret and do not commit this file to git or share the content publicly. If you are using git, then include this file name in .gitignore file.

The below tabs show partially filled .env file content for some of the supported networks.

.env
# Mandatory environment variables

OCEAN_NETWORK=mainnet
OCEAN_NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>

# Optional environment variables

AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.oceanprotocol.com
.env
# Mandatory environment variables

OCEAN_NETWORK=polygon
OCEAN_NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>

# Optional environment variables

AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.oceanprotocol.com
.env
# Mandatory environment variables
OCEAN_NETWORK=development
OCEAN_NETWORK_URL=http://172.15.0.3:8545/
AQUARIUS_URL=http://172.15.0.5:5000
PROVIDER_URL=http://172.15.0.4:8030

# Replace PRIVATE_KEY if needed
PRIVATE_KEY=0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58

Setup dependencies

In this step, all required dependencies will be installed.

Installation & Usage

Let's install Ocean.js library into your current project by running:

npm init
npm i @oceanprotocol/lib@latest dotenv crypto-js [email protected] @truffle/hdwallet-provider

Create a configuration file

A configuration file will read the content of the .env file and initialize the required configuration objects which will be used in the further tutorials. The below scripts creates a Web3 wallet instance and an Ocean's configuration object.

Create the configuration file in the working directory i.e. at the same path where the .env is located.

config.js
require("dotenv").config();
const {
	Aquarius,
	ConfigHelper,
	configHelperNetworks,
} = require("@oceanprotocol/lib");
const ethers = require("ethers");
import fs from "fs";
import { homedir } from "os";

async function oceanConfig() {
	const provider = new ethers.providers.JsonRpcProvider(
		process.env.OCEAN_NETWORK_URL || configHelperNetworks[1].nodeUri
	);
	const publisherAccount = new ethers.Wallet(process.env.PRIVATE_KEY, provider);

	let oceanConfig = new ConfigHelper().getConfig(
		parseInt(String((await publisherAccount.provider.getNetwork()).chainId))
	);
	const aquarius = new Aquarius(oceanConfig?.metadataCacheUri);

	// 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 addresses = JSON.parse(
			// eslint-disable-next-line security/detect-non-literal-fs-filename
			fs.readFileSync(
				process.env.ADDRESS_FILE ||
					`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
				"utf8"
			)
		).development;

		oceanConfig = {
			...oceanConfig,
			oceanTokenAddress: addresses.Ocean,
			fixedRateExchangeAddress: addresses.FixedPrice,
			dispenserAddress: addresses.Dispenser,
			nftFactoryAddress: addresses.ERC721Factory,
			opfCommunityFeeCollector: addresses.OPFCommunityFeeCollector,
		};
	}

	oceanConfig = {
		...oceanConfig,
		publisherAccount: publisherAccount,
		consumerAccount: publisherAccount,
		aquarius: aquarius,
	};

	return oceanConfig;
}

module.exports = {
	oceanConfig,
};

Now you have set up the necessary files and configurations to interact with Ocean Protocol's smart contracts using ocean.js. You can proceed with further tutorials or development using these configurations.

Replace <replace this> with the appropriate values. You can see all the networks configuration on Oceanjs' .

💻
this section
config helper