A collection of TypeScript tools to interact with HypercertsExchange smart contracts, enabling users to sell and buy Hypercerts on the marketplace.
Read the guides if you need help with the implementation.
You can also read the detailed API documentation.
No environment variables are required to run, build or run tests on the SDK.
The HypercertExchangeClient()
allows you to override the API endpoint. This can be useful for developing against a local instance of the API.
To use a locally built version of the SDK in another project, you can use pnpm link
:
cd marketplace-sdk
pnpm install && pnpm run build
cd ../your-project
pnpm link <path to marketplace sdk on you local filesystem>
dev
- Run the SDK in development modebuild
- Build the SDKtest
- Run the testsdocs
- Generate the documentation into thedoc
foldersupabase:types:hypercerts
- Generate types for thedata-staging
database
- User A creates maker order and signs it
- User A registers maker order with API
- Signature on maker order gets verified by API
- If verified correctly, order gets stored in data postgres DB
- Order will live in DB until deleted
- Order will be visible to other users as long as it's valid.
- An order being executed might render it being invalid. A user can invalidate their own orders on request. There are more possible reasons, see the
OrderValidatorCode
enum located in src/types.ts and the guide on order validation.- User B fetches order from API
- User B creates taker order for maker order
- User B signs taker order against maker order using the
HypercertExchangeClient
, found in the marketplace SDK - User B calls the
executeOrder
method on theHypercertExchangeClient
with the taker order, which calls theHypercertExchange
contract in turn. - The
HypercertExchange
contract verifies the signature and executes the order - The
HypercertExchange
contract will emit an event that the order has been executed, which is picked up by the indexer which revalidates the order. If the transaction rendered the order invalid for any further sales, the error codes and validity get updated in the DB.
- Once a maker order is invalidated it's only visible to User A.
- Maker order can be deleted or permanently rendered invalid by declaring the nonce invalid by User A at any time.
Warning
The indexer is not listing to the OrderExecuted event yet, so the order will not be updated in the DB, unless reverified manually.
graph TD
subgraph User A
A1[Creates maker order and signs it]
A2[Registers maker order with API]
end
subgraph API
B1[Receives maker order]
B2[Verifies signature on maker order]
B3[Stores order in Postgres DB]
end
subgraph Postgres DB
C1[Stores order]
C2[Order visible to other users as long as it's valid]
C3[Order validity can be updated]
C4[Order can become invalid due to various reasons]
C5[Marks order as invalid and stores error codes]
end
subgraph User B
D1[Fetches order from API]
D2[Creates taker order for maker order]
D3[Signs taker order against maker order using HypercertExchangeClient]
D4[Calls executeOrder method on HypercertExchangeClient]
end
subgraph HypercertExchange Contract
E1[Verifies signature]
E2[Executes order]
E3[Emits OrderExecuted event]
end
subgraph Indexer
F1[Picks up OrderExecuted event]
F2[Revalidates order]
F3[Updates error codes and validity in DB]
end
subgraph User A
G1[Invalid order is only visible to User A]
G2[Can delete or render order permanently invalid]
end
A1 --> A2
A2 --> B1
B1 --> B2
B2 --> B3
B3 --> C1
C1 --> C2
C2 --> C3
C3 --> D1
C3 --> C4
C4 --> C5
C5 --> C6
D1 --> D2
D2 --> D3
D3 --> D4
D4 --> E1
E1 --> E2
E2 --> E3
E3 --> F1
F1 --> F2
F2 --> F3
C6 --> G1
G1 --> G2