Pricing
What a service costs, read from the chain
v1 read prices from the Ocean subgraph. That is gone — Config has no subgraphUri at all
any more, and nautilus no longer depends on urql or graphql. Prices now come from
contract reads, the same way ocean.js derives them.
For most flows you never need this: access orders whatever is
required. Reach for it when you want to show a price before committing to a purchase.
Two steps
Pricing is read in two calls: what scheme the datatoken uses, then what one order costs.
const = await .('did:ope:1234abcd...')
const = ()[0].
const = (, ) as string
const = .()
const = .()
const = await (, , )
const = await (, , )
.(.)PricingInfo
| Field | Meaning |
|---|---|
schema | 'fixed', 'free' or 'none' |
templateId | Datatoken template: 1 basic, 2 enterprise, 4 confidential EVM |
datatokenAddress | The token being priced |
exchangeId | The fixed-rate exchange id, when schema is 'fixed' |
baseTokenAddress | What the exchange charges in |
baseTokenDecimals | Decimals of that token |
publishMarketFee | The publisher's market fee |
OrderPrice
Every field is a decimal string.
| Field | Meaning |
|---|---|
total | The base-token spend — what the exchange takes |
baseTokenAmount | The same amount, named for what it is |
opcFee | Ocean Protocol Community fee |
publishMarketFee | The publishing market's cut, in its own token |
consumeMarketFee | What your market collects, if you charge anything |
consumeMarket | The { address, fee } this quote was priced with |
total already contains every swap-side fee, so never sum the fields yourself.
Charging a consume-market fee
Your cut is a fraction of the swap, not an amount — '0.01' is 1% — and it needs the
account that collects it. The exchange pays its swap fee to whichever address the order
names, so a fee without a collector is either lost or paid to somebody else.
const = await (, , , {
: '0xYourMarketCollector',
: '0.01' // 1% of the swap
})
// `price` carries the fee, so the order charges what was quoted, to the address it was
// quoted for.
await ({ , , , , : 0, , })Do you already hold an order?
hasReusableOrder answers from what the node reports, rather than reconstructing it from
events — the node returns validOrder when a previous order is still inside the service's
timeout.
if (()) {
// Already paid, still inside the timeout — no new order needed.
}Coming from v1
| v1 | v2 |
|---|---|
getAccessDetails() | getPricingInfo() |
AccessDetails | PricingInfo |
OrderPriceAndFees | OrderPrice |
AssetWithAccessDetails | — read pricing separately from the asset |
| subgraph queries | contract reads |
Try it
npm start -- access:price did:ope:… # what an asset costs right now
npm start -- edit:price did:ope:… 2.95 # reprice a fixed-rate exchangeconfig.ts in examples/ holds ready-made pricing configs per network,
with the payment-token addresses already filled in.