Delivator / skynet

Use Sia Skynet and SkyDB in your Dart and Flutter projects (Decentralized CDN and database)

Home Page:https://pub.dev/packages/skynet

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 <script> 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

dependencies:
  skynet:
    git: https://github.com/redsolver/skynet.git

Usage

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 successful

  final updatedFile = await skynetClient.skydb.getFile(user, datakey);
  print(updatedFile.asString);
}

About

Use Sia Skynet and SkyDB in your Dart and Flutter projects (Decentralized CDN and database)

https://pub.dev/packages/skynet

License:MIT License


Languages

Language:Dart 100.0%