@accret/api-client
Version:
A comprehensive SDK for blockchain data access via Moralis, Alchemy, and Shyft APIs
161 lines (133 loc) • 3.96 kB
Markdown
## Accret API SDK
This SDK provides a unified interface for interacting with EVM and Solana wallets and tokens. All major functions accept a universal input structure and return a standardized response.
### Installation
```bash
npm install @accret/api-client
# or
yarn add @accret/api-client
# or
bun add @accret/api-client
```
### Usage
Using the AccretClient class
```ts
import { AccretClient } from "@accret/api-client";
const client = new AccretClient();
await client.configure({
alchemyApiKey: "YOUR_ALCHEMY_API_KEY",
moralisApiKey: "YOUR_MORALIS_API_KEY",
shyftApiKey: "YOUR_SHYFT_API_KEY",
heliusApiKey: "YOUR_HELIUS_API_KEY",
});
// Example: Get token metadata
const tokenMetadata = await client.getTokenMetadata([
{ address: "0x...", chainId: client.AccretSupportedChain.ETHEREUM_CHAIN },
]);
// Example: Get token price
const tokenPrice = await client.getTokenPrice([
{ address: "0x...", chainId: client.AccretSupportedChain.ETHEREUM_CHAIN },
]);
// Example: Get tokens for wallet
const tokensForWallet = await client.getTokensForWallet([
{ address: "0x...", chainId: client.AccretSupportedChain.ETHEREUM_CHAIN },
{ address: "...", chainId: client.AccretSupportedChain.SOLANA_CHAIN },
]);
// Example: Get transaction history
const txHistory = await client.getTransactionHistory([
{ address: "0x...", chainId: client.AccretSupportedChain.ETHEREUM_CHAIN },
]);
// Example: Get historical token price
const historicalPrice = await client.getHistoricalTokenPrice([
{
address: "0x...",
chainId: client.AccretSupportedChain.ETHEREUM_CHAIN,
startTime: "2024-01-01T00:00:00Z",
endTime: "2024-01-31T23:59:59Z",
interval: client.HistoricalPriceInterval.DAILY,
},
]);
```
### Universal Input Types
#### Token/Wallet Input
```ts
{
address: string; // wallet or token address
chainId: AccretSupportedChain; // enum value for supported chains
}
```
#### Historical Price Input
```ts
{
address: string;
chainId: AccretSupportedChain;
startTime: string; // ISO date string
endTime: string; // ISO date string
interval: HistoricalPriceInterval; // e.g., DAILY, HOURLY
}
```
#### AccretSupportedChain Enum
| **Enum Name** | **Chain ID** |
| --------------- | -------------- |
| ETHEREUM_CHAIN | `eip155:1` |
| BNB_CHAIN | `eip155:56` |
| POLYGON_CHAIN | `eip155:137` |
| BASE_CHAIN | `eip155:8453` |
| ARBITRUM_CHAIN | `eip155:42161` |
| AVALANCHE_CHAIN | `eip155:43114` |
| SOLANA_CHAIN | `solana:501` |
### Available Functions
- Get tokens held by one or more wallets across supported chains.
```ts
getTokensForWallet(addresses: {
address: string,
chainId: AccretSupportedChain
}[])
```
- Get transaction history for one or more wallets.
```ts
getTransactionHistory(addresses: {
address: string,
chainId: AccretSupportedChain
}[])
```
- Get metadata for one or more tokens.
```ts
getTokenMetadata(addresses: {
address: string,
chainId: AccretSupportedChain
}[])
```
- Get current price for one or more tokens.
```ts
getTokenPrice(addresses: {
address: string,
chainId: AccretSupportedChain
}[])
```
- Get historical price data for one or more tokens.
```ts
getHistoricalTokenPrice(addresses: {
address: string,
chainId: AccretSupportedChain,
startTime: string,
endTime: string,
interval: HistoricalPriceInterval
}[])
```
- Get the Accret-supported chain identifier for a given chain/network.
```ts
getAccretSupportedChain({ chain });
```
- Get chain identifiers for a given Accret-supported chain.
```ts
getChainIdentifiers({ chain });
```
### API Keys Required
To use this SDK, you'll need API keys from:
- **Alchemy** (EVM data)
- **Moralis** (EVM data)
- **Shyft** (Solana data)
- **Helius** (Solana data)
These must be provided when initializing the AccretClient.
### License
[MIT](https://github.com/accret/accret-api-client?tab=MIT-1-ov-file)