generated from ChainSafe/yarn-workspaces-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 4
feat!: refactor api #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
f3da187
validate /w team
BeroBurny 47afc40
swap `zod` with `superstruct`
BeroBurny 3956863
first case for api refactor
BeroBurny ce3b88c
move sprinter to separate file
BeroBurny db2a9cf
refactor
BeroBurny 18f768b
smoll fixes
BeroBurny b1151a8
sprinter class docs
BeroBurny c72bc78
add enum :man_shrugging:
BeroBurny ddd45f2
micro bug fixes
BeroBurny c61895f
refactor POC to match new SDK
BeroBurny ed12547
lint
BeroBurny 9c4272d
change sprinter sdk from dependencies to peer dependencies
BeroBurny 2121e83
partially refactor react sdk
BeroBurny b8656c9
react sdk docs and smool fix
BeroBurny 4d73265
fix yarn.lock
BeroBurny c84f104
fix ci
BeroBurny 33ef698
fix yarn command
BeroBurny c5e921d
save
BeroBurny a7f93e3
save general
BeroBurny 56231ea
refactor `sourceChains` behavior for single hop
BeroBurny dd1d8c8
sdk docs v1 on new approach
BeroBurny e46aeed
react docs v1
BeroBurny 7f72af1
Merge branch 'master' into beroburny/api-refactor
BeroBurny 046d431
dirty fix
BeroBurny a75d753
wtf is that? remove! purger!
BeroBurny f45864e
prettify category and push overview into index
BeroBurny eeb6625
fix example response for available tokens
BeroBurny 0589132
fix network list
BeroBurny 2efbfd7
implement remark plugins
BeroBurny fbe318b
fix `recipient`
BeroBurny 7d69042
implement calldata usages
BeroBurny b86162e
gas tips
BeroBurny 9acc443
smoll fix
BeroBurny a4ddc83
refactor gas tip
BeroBurny bc516e4
implement tabs in bridge and call
BeroBurny dfad461
ci / cd
BeroBurny e1fd86c
gas limit
BeroBurny 2566a3c
aggregate
BeroBurny 06a56ac
fix links
BeroBurny 2ca9ae6
breaking changes docs
BeroBurny 33156ae
comments
BeroBurny edc6911
curl example
BeroBurny 6622bd5
address comments regarding method names
BeroBurny 9b04fb4
fix breaking changes doc
BeroBurny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,46 +4,99 @@ title: Quick Start | |
| sidebar_position: 2 | ||
| --- | ||
|
|
||
| You have two main options for interacting with Sprinter: | ||
| ## Quick Examples | ||
|
|
||
| Jump to the section that fits your development needs: | ||
|
|
||
| - [Using the SDK](#using-the-sdk) | ||
| - [Using the React SDK](#using-the-react-sdk) | ||
| - [Calling API Endpoints Directly](#calling-api-endpoints-directly) | ||
|
|
||
| You have three main options for interacting with Sprinter, depending on your development environment and the level of control you need: | ||
|
|
||
| - **Using the SDK**: Ideal for developers working in TypeScript or modern JavaScript frameworks. The SDK provides a simple, unified interface for retrieving intent-based solutions from Sprinter, helping developers easily determine the actions or transactions users should execute on the blockchain. | ||
|
|
||
| - **Using the React SDK**: Designed for React developers, this option offers hooks and context that make it simple to access intent-based solutions provided by Sprinter within React components, allowing seamless interaction with the intent engine. | ||
|
|
||
| - **Calling API Endpoints Directly**: This option is best suited for developers who want full control over API interactions. It’s flexible and can be used in any programming environment, but requires a deeper understanding of the Sprinter protocol. We recommend this for advanced users or those working in non-JavaScript environments. | ||
|
|
||
| ### Using the SDK | ||
|
|
||
| Using the Sprinter SDK provides a convenient and unified interface for blockchain interactions, complete with TypeScript support for enhanced type safety and a better development experience. This approach is recommended for developers working with TypeScript or popular web frameworks. | ||
| The Sprinter SDK provides a streamlined interface for retrieving intent-based solutions from Sprinter, with built-in TypeScript support to ensure type safety and an enhanced development experience. This approach is recommended for developers who are comfortable with TypeScript or those working in modern web frameworks. | ||
|
|
||
| **Quick Example** | ||
|
|
||
| Here's a quick example of how to use the SDK in your project: | ||
| Here’s a quick example of how to use the SDK in your project: | ||
|
|
||
| ```typescript | ||
| import { Sprinter } from '@chainsafe/sprinter-sdk'; | ||
| import { Sprinter, Environment } from '@chainsafe/sprinter-sdk'; | ||
|
|
||
| const sprinter = new Sprinter(window.ethereum); | ||
| const sprinter = new Sprinter({ baseUrl: Environment.MAINNET }); | ||
|
|
||
| sprinter.getUserBalances().then(console.log); | ||
| sprinter.getUserBalances('0xYourAddressHere').then(console.log); | ||
| ``` | ||
|
|
||
| For a more detailed guide on setting up and using the SDK, refer to the [SDK Documentation](03-sdk/01-overview.md). | ||
| For more details on using the SDK, refer to the [SDK Documentation](./sdk). | ||
|
|
||
| ### Calling API Endpoints Directly | ||
| ### Using the React SDK | ||
|
|
||
| If you prefer more control or wish to implement the solution in a different programming language, you can directly interact with the API endpoints provided by Sprinter. | ||
| If you're building a React application, you can use the Sprinter React SDK (`@chainsafe/sprinter-react`), which provides hooks and context to interact with the Sprinter core SDK. | ||
|
|
||
| **Quick Example** | ||
|
|
||
| Here’s how you can call the API directly using JavaScript's Fetch API: | ||
| Here’s how to set up a simple React component to fetch user balances: | ||
|
|
||
| ```tsx | ||
| import React, { useEffect } from 'react'; | ||
| import { SprinterContext, useSprinterBalances } from '@chainsafe/sprinter-react'; | ||
| import { Environment } from '@chainsafe/sprinter-sdk'; | ||
|
|
||
| function BalancesComponent() { | ||
| const { balances, getUserBalances } = useSprinterBalances('0xYourAddressHere'); | ||
|
|
||
| useEffect(() => { | ||
| getUserBalances(); | ||
| }, [getUserBalances]); | ||
|
|
||
| if (balances.loading) return <div>Loading...</div>; | ||
| if (balances.error) return <div>Error: {balances.error}</div>; | ||
|
|
||
| return ( | ||
| <ul> | ||
| {Object.entries(balances.data || {}).map(([symbol, balanceEntry]) => ( | ||
| <li key={symbol}>{symbol}: {balanceEntry.total}</li> | ||
| ))} | ||
| </ul> | ||
| ); | ||
| } | ||
|
|
||
| function App() { | ||
| return ( | ||
| <SprinterContext baseUrl={Environment.MAINNET}> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe change the name of |
||
| <BalancesComponent /> | ||
| </SprinterContext> | ||
| ); | ||
| } | ||
|
|
||
| export default App; | ||
| ``` | ||
|
|
||
| For detailed usage, check the [React SDK Documentation](./react-sdk). | ||
|
|
||
| ### Calling API Endpoints Directly | ||
|
|
||
| This approach provides more control over how you interact with the API but is generally suited for advanced users or developers working in non-JavaScript environments. | ||
|
|
||
| :::caution For Advanced Users | ||
| Calling the API directly provides the most flexibility but requires a deeper understanding of the Sprinter protocol and how to structure API requests. It's recommended for experienced developers who need full control over API interactions. | ||
| ::: | ||
|
|
||
| **Quick Example** | ||
|
|
||
| ```javascript | ||
| const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; | ||
| const tokenSymbol = "USDC"; | ||
| const baseUrl = "https://api.sprinter.buildwithsygma.com/"; | ||
| Here’s how you can call the API directly using `curl`: | ||
|
|
||
| fetch(`${baseUrl}/accounts/${ownerAddress}/assets/fungible/${tokenSymbol}`) | ||
| .then(response => response.json()) | ||
| .then(data => console.log(data)) | ||
| .catch(error => console.error('Error fetching user fungible tokens:', error)); | ||
| ```bash | ||
| curl -X GET "https://api.sprinter.buildwithsygma.com/accounts/0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519/assets/fungible/USDC" | ||
| ``` | ||
|
|
||
| For a comprehensive list of available endpoints and how to use them, check out the [API Documentation](04-api/01-api-usage.md). | ||
| For a comprehensive list of available endpoints and how to use them, check out the [API Documentation](https://api.sprinter.buildwithsygma.com/swagger/index.html). | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.