@unicitylabs/sphere-sdk 0.1.8 → 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 +47 -2
- package/dist/core/index.cjs +2019 -374
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +631 -58
- package/dist/core/index.d.ts +631 -58
- package/dist/core/index.js +2018 -373
- package/dist/core/index.js.map +1 -1
- package/dist/impl/browser/index.cjs +312 -12
- package/dist/impl/browser/index.cjs.map +1 -1
- package/dist/impl/browser/index.js +312 -12
- package/dist/impl/browser/index.js.map +1 -1
- package/dist/impl/browser/ipfs.cjs +4 -2
- package/dist/impl/browser/ipfs.cjs.map +1 -1
- package/dist/impl/browser/ipfs.js +4 -2
- package/dist/impl/browser/ipfs.js.map +1 -1
- package/dist/impl/nodejs/index.cjs +345 -14
- package/dist/impl/nodejs/index.cjs.map +1 -1
- package/dist/impl/nodejs/index.d.cts +224 -14
- package/dist/impl/nodejs/index.d.ts +224 -14
- package/dist/impl/nodejs/index.js +345 -14
- package/dist/impl/nodejs/index.js.map +1 -1
- package/dist/index.cjs +2255 -382
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1046 -7571
- package/dist/index.d.ts +1046 -7571
- package/dist/index.js +2266 -403
- package/dist/index.js.map +1 -1
- package/dist/l1/index.cjs.map +1 -1
- package/dist/l1/index.d.cts +7 -0
- package/dist/l1/index.d.ts +7 -0
- package/dist/l1/index.js.map +1 -1
- package/package.json +1 -1
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
|
-
//
|
|
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('
|
|
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**:
|