Example Repository
A complete working example using this integration approach.
@echoxyz/sonar-react library.
All authentication and API calls happen client-side, with tokens stored in browser storage.
For apps with a backend, consider the Frontend with Backend approach for improved security.
How it works
Installation
Configuration
Wrap your app inSonarProvider:
Implementing the OAuth flow
Sonar uses OAuth to allow users to authenticate and authorize your application to access their data. You will need buttons that allow users to login and logout from Sonar. Logging in will redirect the user to the Sonar site to login. If they haven’t yet authorized your application, they will be prompted to do so.redirectURI with code and state querystring parameters.
You will need a page at your redirectURI that will handle the OAuth callback.
Fetching the state of a user’s Sonar entities
You can fetch the state of a user’s Sonar entities with theuseSonarEntities hook.
useSonarEntity hook.
See the example app EntityStateDescription
for more detail on how to interpret the state and display it to the user.
Running pre-purchase checks
Once the sale is live, you can use theuseSonarPurchase hook to run pre-purchase checks.
Reference docs for the useSonarPurchase hook.
If the entity is not ready to purchase, the reason why will be returned in the failureReason field.
If a liveness check is required, the livenessCheckURL field will be returned and you should redirect the user to this URL to complete the liveness check.
Generating a purchase permit to send to the sale contract
If the entity is ready to purchase and you are running an onchain sale, you will need to:- Use the
generatePurchasePermitfunction to fetch a signed purchase permit from Sonar - Construct a transaction including the purchase permit and have the user sign it
- Send the transaction to the sale contract
wagmi library.
First, you will need to get a copy of the sale contract’s ABI and include it in your project.
If you are using the generic SettlementSale contract,
you can find the ABI here.
Then, let’s create a hook for managing the transaction lifecycle.
commitWithPermit function as part of a button click handler.
Further reading
Retrieving user investment history
This is an optional feature for retrieving users past Echo private group investments.
useEntityInvestmentHistory hook.
This shows all deals they’ve previously participated in, which can be useful if you are intending to give reputational boost/extra points if they have invested in a particulat deal.
Reference docs for the useEntityInvestmentHistory hook.