@unicitylabs/sphere-sdk 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -112,9 +112,13 @@ if (created && generatedMnemonic) {
112
112
  // Get identity (L3 DIRECT address is primary)
113
113
  console.log('Address:', sphere.identity?.directAddress);
114
114
 
115
- // Check balance
115
+ // Get assets with price data
116
+ const assets = await sphere.payments.getAssets();
117
+ console.log('Assets:', assets);
118
+
119
+ // Get total portfolio value in USD (requires PriceProvider)
116
120
  const balance = await sphere.payments.getBalance();
117
- console.log('L3 Balance:', balance);
121
+ console.log('Total USD:', balance); // number | null
118
122
 
119
123
  // Send tokens
120
124
  const result = await sphere.payments.send({
@@ -155,6 +159,47 @@ const providers = createBrowserProviders({
155
159
  });
156
160
  ```
157
161
 
162
+ ## Price Provider (Optional)
163
+
164
+ Enable fiat price display by adding a `price` config. Currently supports CoinGecko API (free and pro tiers).
165
+
166
+ ```typescript
167
+ // With CoinGecko (free tier, no API key)
168
+ const providers = createBrowserProviders({
169
+ network: 'testnet',
170
+ price: { platform: 'coingecko' },
171
+ });
172
+
173
+ // With CoinGecko Pro
174
+ const providers = createBrowserProviders({
175
+ network: 'testnet',
176
+ price: { platform: 'coingecko', apiKey: 'CG-xxx' },
177
+ });
178
+
179
+ const { sphere } = await Sphere.init({ ...providers, autoGenerate: true });
180
+
181
+ // Total portfolio value in USD
182
+ const totalUsd = await sphere.payments.getBalance();
183
+ // 1523.45
184
+
185
+ // Assets with price data
186
+ const assets = await sphere.payments.getAssets();
187
+ // [{ coinId, symbol, totalAmount, priceUsd: 97500, fiatValueUsd: 975.00, change24h: 2.3, ... }]
188
+ ```
189
+
190
+ Without `price` config, `getBalance()` returns `null` and price fields in `getAssets()` are `null`. All other functionality works normally.
191
+
192
+ You can also set the price provider after initialization:
193
+
194
+ ```typescript
195
+ import { createPriceProvider } from '@unicitylabs/sphere-sdk';
196
+
197
+ sphere.setPriceProvider(createPriceProvider({
198
+ platform: 'coingecko',
199
+ apiKey: 'CG-xxx',
200
+ }));
201
+ ```
202
+
158
203
  ## Testnet Faucet
159
204
 
160
205
  To get test tokens on testnet, you **must first register a nametag**: