Local setup for running & testing ocean.py
On this page, we continue our journey from installation part, to do setup for local testing. Local setup means that we will use Ganache as local blockchain where we can effectuate transactions and all the services point to this network.
Here are the following steps for configuring ocean.py on Ganache network using barge.
Ahoy there, matey! 🌊⚓️ When it comes to setting up ocean.py locally, we're diving into the world of Docker containers. These clever containers hold our trusty local blockchain nodes (Ganache) and the mighty Ocean middleware (Aquarius metadata cache and Provider to aid in consuming data assets). But fear not, for a smooth sailing experience, you'll need to ensure the following Docker components are shipshape and ready to go:
So hoist the anchor, prepare your Docker crew, and let's embark on an exciting voyage with ocean.py! 🚢⛵️
bargeruns ganache (local blockchain), Provider (data service), and Aquarius (metadata cache).
Barge helps you quickly become familiar with Ocean, because the local blockchain has low latency and no transaction fees.\
In a new console:
# Grab repo
git clone https://github.com/oceanprotocol/barge
# Clean up old containers (to be sure)
docker system prune -a --volumes
# Run barge: start Ganache, Provider, Aquarius; deploy contracts; update ~/.ocean
Let barge do its magic and wait until the blockchain is fully synced. That means when you start to see continuosly
(You don't need to do anything in this step, it's just useful to understand.)
Brownie's network configuration file is at
When running locally, Brownie will use the chain listed under
development, having id
development. This refers to Ganache, which is running in Barge.
From here on, go to a console different than Barge. (E.g. the console where you installed Ocean, or a new one.)
First, ensure that you're in the working directory, with venv activated:
For this tutorial Alice is the publisher of the dataset and Bob is the consumer of the dataset. As a Linux user, you'll use "
export" for setting the private keys. In the same console:
# keys for alice and bob
# key for minting fake OCEAN
In the same console, run Python console:
In the Python console:
# Create Ocean instance
from ocean_lib.web3_internal.utils import connect_to_network
from ocean_lib.example_config import get_config_dict
config = get_config_dict("development")
from ocean_lib.ocean.ocean import Ocean
ocean = Ocean(config)
# Create OCEAN object. Barge auto-created OCEAN, and ocean instance knows
OCEAN = ocean.OCEAN_token
# Mint fake OCEAN to Alice & Bob
from ocean_lib.ocean.mint_fake_ocean import mint_fake_OCEAN
# Create Alice's wallet
from brownie.network import accounts
alice_private_key = os.getenv("TEST_PRIVATE_KEY1")
alice = accounts.add(alice_private_key)
assert alice.balance() > 0, "Alice needs ETH"
assert OCEAN.balanceOf(alice) > 0, "Alice needs OCEAN"
# Create additional wallets. While some flows just use Alice wallet, it's simpler to do all here.
bob_private_key = os.getenv('TEST_PRIVATE_KEY2')
bob = accounts.add(bob_private_key)
assert bob.balance() > 0, "Bob needs ETH"
assert OCEAN.balanceOf(bob) > 0, "Bob needs OCEAN"
# Compact wei <> eth conversion
from ocean_lib.ocean.util import to_wei, from_wei