Technical details about most used ocean.py functions
At the beginning of most flows, we create an ocean object, which is an instance of class Ocean. It exposes useful information, including the following:
The Ocean class is the entry point into Ocean Procol.
In order to initialize a Ocean object, you must provide config_dict which is a Dictionary instance and optionally a DataServiceProvider instance.
Parameters
config_dict: dict which is mandatory and it contains the configuration as dictionary format.
data_provider: Optional[DataProvider] which is optional with a default value of None. If it is not provided, the constructor will instantiate a new one from scratch.
Returns
None
Defined in
config(self) -> dict
It is a helper method for retrieving the user's configuration for ocean.py.
It can be called only by Ocean object and returns a python dictionary.
Returns
dict
Configuration fields as dictionary.
Defined in
ocean_address(self) -> str
It is a helper method for retrieving the OCEAN's token address.
It can be called only by Ocean object and returns the address as a string.
Returns
str
OCEAN address for that network.
Defined in
ocean_token(self) -> DatatokenBase
OCEAN(self) -> DatatokenBase as alias for the above option
It is a helper method for retrieving the OCEAN token object (Datatoken class).
It can be called within Ocean class and returns the OCEAN Datatoken.
Returns
DatatokenBase
OCEAN token as DatatokenBase object.
Defined in
data_nft_factory(self) -> DataNFTFactoryContract
It is a property for getting Data NFT Factory object for the singleton smart contract.
It can be called within Ocean class and returns the DataNFTFactoryContract instance.
Returns
DataNFTFactoryContract
Data NFT Factory contract object which access all the functionalities available from smart contracts in Python.
Defined in
dispenser(self) -> Dispenser
Dispenser is represented by a faucet for free data.
It is a property for getting Dispenser object for the singleton smart contract.
It can be called within Ocean class and returns the Dispenser instance.
Returns
Dispenser
Dispenser contract object which access all the functionalities available from smart contracts in Python.
Defined in
fixed_rate_exchange(self) -> FixedRateExchange
Exchange is used for priced data.
It is a property for getting FixedRateExchange object for the singleton smart contract.
It can be called within Ocean class and returns the FixedRateExchange instance.
Returns
FixedRateExchange
Fixed Rate Exchange contract object which access all the functionalities available from smart contracts in Python.
Defined in
get_nft_token(self, token_adress: str) -> DataNFT
It is a getter for a specific data NFT object based on its checksumed address.
It can be called within Ocean class which returns the DataNFT instance based on string token_address specified as parameter.
Parameters
token_address - string checksumed address of the NFT token that you are searching for.
Returns
DataNFT
Data NFT object which access all the functionalities available for ERC721 template in Python.
It is a getter for a specific datatoken object based on its checksumed address.
It can be called within Ocean class with a string token_address as parameter which returns the DatatokenBase instance depending on datatoken's template index.
Parameters
token_address - string checksumed address of the datatoken that you are searching for.
Returns
DatatokenBase
Datatoken object which access all the functionalities available for ERC20 templates in Python.
get_ocean_token_address function is an utilitary function which gets the address from address.json file
@enforce_types
def get_ocean_token_address(config_dict: dict) -> str:
"""Returns the OCEAN address for given network or web3 instance
Requires either network name or web3 instance.
"""
addresses = get_contracts_addresses(config_dict)
return Web3.toChecksumAddress(addresses.get("Ocean").lower()) if addresses else None
OCEAN Token Object
Source code
@property
@enforce_types
def OCEAN_token(self) -> DatatokenBase:
return DatatokenBase.get_typed(self.config, self.OCEAN_address)
@property
@enforce_types
def OCEAN(self): # alias for OCEAN_token
return self.OCEAN_token