WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 73d42fa

Browse files
Create list blob example (#10)
* Create list blob example * [tables] Add list blob example * Add an example to store AI generated images on shelby (#11) * add example to store ai generated images on shelby * address comments * fmt --------- Co-authored-by: Maayan <[email protected]>
1 parent 86f15c9 commit 73d42fa

File tree

7 files changed

+222
-0
lines changed

7 files changed

+222
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This Turborepo includes the following example applications:
3131
| `@shelby-protocol/ai-image-generation` | Shelby AI image generation example | [`apps/ai-image-generation`](./apps/ai-image-generation) |
3232
| `@shelby-protocol/cross-chain-accounts` | Shelby cross chain accounts example | [`apps/cross-chain-accounts`](./apps/cross-chain-accounts) |
3333
| `@shelby-protocol/download-example` | An example app to demonstrate downloading blobs using the Shelby SDK | [`apps/download-blob`](./apps/download-blob) |
34+
| `@shelby-protocol/list-example` | An example app to demonstrate listing blobs using the Shelby SDK | [`apps/list-blob`](./apps/list-blob) |
3435
| `@shelby-protocol/upload-example` | An example app to demonstrate uploading blobs using the Shelby SDK | [`apps/upload-blob`](./apps/upload-blob) |
3536

3637
<!-- APPS_TABLE_END -->

apps/list-blob/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SHELBY_ACCOUNT_ADDRESS=0xYourAccountAddressHere
2+
SHELBY_API_KEY=AG-YourApiKeyHere

apps/list-blob/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Shelby List Blob Example
2+
3+
An example application demonstrating how to list blobs from the Shelby protocol using the Shelby SDK. This app retrieves and displays all blobs that have been uploaded to a Shelby account.
4+
5+
## Prerequisites
6+
7+
- Node.js >= 22
8+
- pnpm package manager
9+
- A Shelby account with uploaded blobs
10+
- Shelby API key
11+
12+
## Installation
13+
14+
1. Clone the repository and navigate to the list-blob directory:
15+
```bash
16+
cd apps/list-blob
17+
```
18+
19+
2. Install dependencies:
20+
```bash
21+
pnpm install
22+
```
23+
24+
## Environment Variables
25+
26+
Create a `.env` file in the root of this project directory with the following required environment variables. You can copy the `.env.example` file as a starting point:
27+
28+
```bash
29+
cp .env.example .env
30+
```
31+
32+
Then update the values in your `.env` file:
33+
34+
```env
35+
SHELBY_ACCOUNT_ADDRESS=your_account_address_here
36+
SHELBY_API_KEY=your_api_key_here
37+
```
38+
39+
More information on obtaining an API key on the [Shelby docs site](https://docs.shelby.xyz/sdks/typescript/acquire-api-keys).
40+
41+
## Usage
42+
43+
Run the example using the `bloblist` script:
44+
45+
```bash
46+
pnpm bloblist
47+
```
48+
49+
This will execute the TypeScript file directly using tsx with the environment variables from your `.env` file.
50+
51+
### Alternative Execution
52+
53+
You can also run the TypeScript file directly using tsx:
54+
55+
```bash
56+
npx tsx --env-file=.env src/index.ts
57+
```
58+
59+
## How It Works
60+
61+
1. **Environment Validation**: The app first validates that all required environment variables are set
62+
2. **Client Initialization**: Creates a Shelby client instance connected to the Shelbynet network
63+
3. **Account Setup**: Uses the account address from the environment variable
64+
4. **Blob Listing**: Retrieves a list of all blobs associated with the specified Shelby account
65+
5. **Display Results**: Shows blob metadata including name, size, and expiration date
66+
67+
## Output
68+
69+
When successful, this example will:
70+
- Connect to the Shelby network
71+
- Retrieve all blobs from the specified account
72+
- Display the total number of blobs found
73+
- For each blob, show:
74+
- Blob name
75+
- File size in bytes
76+
- Expiration timestamp
77+
78+
Example output:
79+
```
80+
Found 3 blob(s)
81+
· whitepaper.pdf — 1024567 bytes, expires: 2025-10-16T15:30:00.000Z
82+
· document.txt — 2048 bytes, expires: 2025-10-17T10:45:00.000Z
83+
· image.png — 512000 bytes, expires: 2025-10-18T08:20:00.000Z
84+
```
85+
86+
## Troubleshooting
87+
88+
### Common Issues
89+
90+
1. **SHELBY_ACCOUNT_ADDRESS is not set in .env**
91+
- Ensure you have created a `.env` file with the required variables
92+
- Check that the variable name is spelled correctly
93+
- Verify the account address format is valid
94+
95+
2. **SHELBY_API_KEY is not set in .env**
96+
- Verify your API key is correctly set in the `.env` file
97+
- Ensure there are no extra spaces or quotes around the API key
98+
99+
3. **No blobs found**
100+
- Verify that the account address contains uploaded blobs
101+
- Check that you're using the correct account address
102+
- Ensure blobs haven't expired
103+
104+
4. **Rate limit exceeded (429)**
105+
- Wait a moment before retrying
106+
- Consider implementing exponential backoff for production use
107+
108+
5. **Server errors (500)**
109+
- This indicates an issue with the Shelby service
110+
- Contact Shelby support if this occurs repeatedly

apps/list-blob/package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@shelby-protocol/list-example",
3+
"version": "1.0.0",
4+
"description": "An example app to demonstrate listing blobs using the Shelby SDK",
5+
"type": "module",
6+
"scripts": {
7+
"bloblist": "tsx --env-file=.env src/index.ts",
8+
"lint": "biome check .",
9+
"fmt": "biome check . --write"
10+
},
11+
"keywords": [
12+
"shelby",
13+
"sdk",
14+
"blob",
15+
"storage"
16+
],
17+
"author": "Akasha <[email protected]>",
18+
"license": "MIT",
19+
"dependencies": {
20+
"@aptos-labs/ts-sdk": "^5.1.1",
21+
"@shelby-protocol/sdk": "^0.0.4"
22+
},
23+
"devDependencies": {
24+
"@biomejs/biome": "2.2.4",
25+
"tsx": "^4.20.5",
26+
"typescript": "^5.9.2",
27+
"vitest": "^3.2.4"
28+
},
29+
"engines": {
30+
"node": ">=22"
31+
}
32+
}

apps/list-blob/src/index.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { AccountAddress, Network } from "@aptos-labs/ts-sdk";
2+
import { ShelbyNodeClient } from "@shelby-protocol/sdk/node";
3+
4+
if (!process.env.SHELBY_API_KEY) {
5+
throw new Error("Missing SHELBY_API_KEY");
6+
}
7+
if (!process.env.SHELBY_ACCOUNT_ADDRESS) {
8+
throw new Error("Missing SHELBY_ACCOUNT_ADDRESS");
9+
}
10+
11+
// 1) Initialize a Shelby client (auth via API key; target shelbynet).
12+
const client = new ShelbyNodeClient({
13+
network: Network.SHELBYNET,
14+
apiKey: process.env.SHELBY_API_KEY, // ensure .env is loaded
15+
});
16+
17+
// 2) Parse the account address you'll download from.
18+
// ⚠️ This should be the *same account* that previously uploaded blobs.
19+
const account = AccountAddress.fromString(process.env.SHELBY_ACCOUNT_ADDRESS);
20+
21+
// 3) Ask Shelby for a list of the account's blobs.
22+
const blobs = await client.coordination.getAccountBlobs({ account });
23+
24+
// 4) For each blob, show its metadata.
25+
console.log(`Found ${blobs.length} blob(s)`);
26+
for (const blob of blobs) {
27+
console.log(
28+
${blob.name}${blob.size} bytes, expires: ${new Date(blob.expirationMicros / 1000).toISOString()}`,
29+
);
30+
}

apps/list-blob/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "bundler",
6+
"allowSyntheticDefaultImports": true,
7+
"esModuleInterop": true,
8+
"allowJs": true,
9+
"strict": true,
10+
"skipLibCheck": true,
11+
"forceConsistentCasingInFileNames": true,
12+
"declaration": true,
13+
"declarationMap": true,
14+
"sourceMap": true,
15+
"outDir": "./dist",
16+
"rootDir": "./src",
17+
"resolveJsonModule": true,
18+
"isolatedModules": true,
19+
"noEmit": false,
20+
"lib": ["ES2022", "DOM"],
21+
"types": ["node", "vitest/globals"]
22+
},
23+
"include": ["src/**/*"],
24+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
25+
}

pnpm-lock.yaml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)