https://github.com/redsolver/skynet
Use Sia Skynet and SkyDB in your Dart and Flutter projects (Decentralized CDN and database)
https://github.com/redsolver/skynet
dart flutter skydb skynet
Last synced: 23 days ago
JSON representation
Use Sia Skynet and SkyDB in your Dart and Flutter projects (Decentralized CDN and database)
- Host: GitHub
- URL: https://github.com/redsolver/skynet
- Owner: redsolver
- License: mit
- Created: 2020-10-16T13:48:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-16T15:49:46.000Z (over 2 years ago)
- Last Synced: 2025-03-28T00:05:59.268Z (about 1 month ago)
- Topics: dart, flutter, skydb, skynet
- Language: Dart
- Homepage: https://pub.dev/packages/skynet
- Size: 189 KB
- Stars: 25
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Skynet SDK for Dart
Use Sia Skynet and SkyDB in your Dart and Flutter projects (Decentralized CDN and database)
This package allows you to use the decentralized SkyDB (https://blog.sia.tech/skydb-a-mutable-database-for-the-decentralized-web-7170beeaa985) and upload files to Skynet.
It also supports Dart-to-JS bindings for MySky and popular DACs (Profile DAC, Feed DAC and Social DAC).
## Breaking changes in version 4.0.0
You now have to use the `SkynetClient()` instance for all operations. See the example below for details or contact me on Discord if you need help migrating your project.
## Imports you need
### `import 'package:skynet/skynet.dart';`
Fully supported on **native** and **web**.
- Upload files or directories to Skynet
- Use SkyDB and the registry directly
- Resolve portal-independent links
- Use the `setJSON` and `getJSON` MySky methods if you have the user's seed
- Use the experimental WebSocket endpoint### `import 'package:skynet/mysky.dart';`
Only supported on **web**, requires importing `skynet-js` using a `` tag.
- Use all MySky methods
### `import 'package:skynet/dacs.dart';`
Most read-only methods supported on **native** and **web**. All methods which write data require MySky and only work on **web**.
- Profile DAC
- Feed DAC
- Social DAC## Install
```yaml
dependencies:
skynet:
git: https://github.com/redsolver/skynet.git
```## Usage
```dart
import 'dart:convert';
import 'dart:typed_data';import 'package:skynet/skynet.dart';
import 'package:convert/convert.dart';void main() async {
final skynetClient = SkynetClient('siasky.net');final user = SkynetUser.fromSeedAsync(
hex.decode(
'788dddf5232807611557a3dc0fa5f34012c2650526ba91d55411a2b04ba56164'),
);
await user.init();print(user.id); // Public User ID
final datakey = 'my-awesome-datakey';
try {
final currentFile = await skynetClient.skydb.getFile(user, datakey);
print(currentFile.asString);
} catch (e) {
// ! getFile throws an Exception if no data is found
}final success = await skynetClient.skydb.setFile(
user,
datakey,
SkyFile(
content: Uint8List.fromList(
utf8.encode('Hello, world!')), // The content you want to store
filename: 'note.txt',
type:
'text/plain', // Content type (Other examples: application/json or image/png)
),
);
print(success); // Is true when the operation was successfulfinal updatedFile = await skynetClient.skydb.getFile(user, datakey);
print(updatedFile.asString);
}
```