π Ocean Protocol β Remote Publishing & Access Script
This Python script automates the publication, access, and payment flow of a dataset on the Ocean Protocol, using the Polygon Mumbai testnet. It integrates data asset publishing, token-based access control, smart contract payments, and Flask-based API endpoints.
π Script Summary
publish_access_remote.py performs the following:
- Initializes Ocean Protocol and Web3 providers.
- Creates buyer and seller accounts with pre-funded test wallets.
- Publishes a dataset to IPFS and registers it as an Ocean asset.
- Allows access and consumption of the dataset by a designated buyer.
- Triggers payment between buyer and seller using a custom smart contract.
- Exposes an API endpoint (
/trigger_payment) to initiate on-chain payment flows.
π§© Key Dependencies
Below are the main Python libraries used, with explanations:
πΉ ocean-lib
- SDK for interacting with the Ocean Protocol.
- Key classes used:
Ocean β Core object for asset and token management.
AssetArguments, DatatokenArguments, DispenserArguments β For publishing assets.
DatatokenBase β For interacting with datatokens.
to_wei() β For unit conversion.
πΉ web3.py
- Ethereum/Web3 library to send transactions, estimate gas, encode data, and interact with smart contracts.
- Used for:
- Custom contract interactions (e.g.,
approve, triggerPayment)
- Reading/writing balances and allowances
πΉ eth-account
- Used to derive account objects from private keys.
πΉ requests
- For external API calls (e.g., fetching OCEAN/EUR price from CoinGecko).
πΉ flask
- Creates a lightweight HTTP API endpoint:
/trigger_payment handles POST requests to process payments between buyers and sellers.
π§ Setup Instructions
1. Install Requirements
pip install ocean-lib web3 eth-account flask requests