https://github.com/duneanalytics/hooks
https://github.com/duneanalytics/hooks
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/duneanalytics/hooks
- Owner: duneanalytics
- Created: 2024-10-17T04:40:06.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-29T12:27:34.000Z (about 1 year ago)
- Last Synced: 2025-05-29T14:06:36.205Z (about 1 year ago)
- Language: TypeScript
- Size: 157 KB
- Stars: 5
- Watchers: 8
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React Hooks for Sim APIs (DEPRECATED - NO LONGER MAINTAINED)
> This repository is **no longer maintained and has been deprecated**. Please integrate directly with the [Sim API endpoints](https://docs.sim.dune.com/) instead of using this repo.
This project integrates with the [Dune's Sim APIs](https://sim.dune.com/) to provide easy access to token balances and transaction data for given wallets. It uses the `SimProvider` to manage API key authorization and provides convenient React hooks for fetching token balances and paginated transaction data.
# Prerequisites
Please use Node.js >= v20.9.0 for development.
# Installation
To get started, install the required dependencies:
```bash
npm install @duneanalytics/hooks
```
# Provider Setup
To use the Sim APIs wrap your application in the `SimProvider` and provide your Sim API key:
```javascript
import { SimProvider } from "@duneanalytics/hooks";
const App = () => (
{/* Your app components */}
);
```
# Props
- simApiKey: Required. The API key to authenticate your requests with Sim APIs.
# Hooks
## useTokenBalances
Fetches token balances for a specific wallet address.
### Example Usage
```javascript
import { useTokenBalances } from "@duneanalytics/hooks";
const MyComponent = ({ account }) => {
const { data, isLoading, error, nextPage, previousPage, currentPage } =
useTokenBalances(account.address, {});
if (isLoading) return
Loading...
;
if (error) return Error: {error.message}
;
return (
{data.balances.map((balance) => (
-
{balance.tokenSymbol}: {balance.amount}
))}
Previous Page
Next Page
Current Page: {currentPage + 1}
);
};
```
### Parameters
- walletAddress: Required. The Ethereum wallet address for which to fetch token balances.
- params: Optional. Additional parameters for the request (e.g., chain or token filters).
### Returns
- data: Contains the list of token balances.
- isLoading: A boolean indicating whether the request is in progress.
- error: Contains any error that occurred during the request.
## useTransactions
Fetches paginated transaction data for a specific wallet address.
### Example Usage
```javascript
import { useTransactions } from "@duneanalytics/hooks";
const TransactionHistory = ({ account }) => {
const {
data: transactionData,
isLoading,
error,
nextPage,
previousPage,
currentPage,
} = useTransactions(account.address, {});
if (isLoading) return
Loading transactions...
;
if (error) return Error: {error.message}
;
return (
{transactionData.transactions.map((tx) => (
-
{tx.from} → {tx.to} | Block: {tx.block_number}
))}
Previous Page
Next Page
Current Page: {currentPage + 1}
);
};
```
### Parameters
- walletAddress: Required. The Ethereum wallet address for which to fetch transactions.
- params: Optional. Additional parameters for the request (e.g., chain or block filters).
### Returns
- data: Contains the transaction data for the current page.
- isLoading: A boolean indicating whether the request is in progress.
- error: Contains any error that occurred during the request.
- nextPage: Function to fetch the next page of transactions.
- previousPage: Function to fetch the previous page of transactions.
- currentPage: The current page number (0-based index).
### Error Handling
Both hooks return an error object that you can use to handle and display errors.
```javascript
if (error) {
console.error("Error fetching data:", error.message);
return
Error: {error.message}
;
}
```
# Deploying
If you have the power to deploy, you can run the following commands to deploy the package to the npm registry:
First tag a new version of the package:
_note you can also use `minor` or `major` instead of `patch` to bump the version number accordingly_
```bash
npm version patch
```
When you make any changes, please make sure that the tests pass.
```bash
npm test
```
Then run the following commands to deploy the package to the npm registry:
```bash
npm run build
npm publish --access public
```
# License
This project is licensed under the MIT License.