nkn_sdk_flutter 0.0.2 copy "nkn_sdk_flutter: ^0.0.2" to clipboard
nkn_sdk_flutter: ^0.0.2 copied to clipboard

outdated

Flutter implementaion of NKN client and wallet SDK. Send and receive data for free between any NKN clients regardless their network condition without setting up a server or relying on any third party [...]

nkn-sdk-flutter #

Usage #

install #

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Wallet.install();
  Client.install();
  runApp(MyApp());
}

Wallet #

Create wallet:

Wallet wallet = await Wallet.create(null, config: WalletConfig(password: '123'));
print(wallet.address);
print(wallet.seed);
print(wallet.publicKey);

Export wallet to JSON string, where sensitive contents are encrypted by password provided in config:

wallet.keystore;

By default the wallet will use RPC server provided by nkn.org. Any NKN full node can serve as a RPC server. To create a wallet using customized RPC server:

Wallet wallet = await Wallet.create(null, config: WalletConfig(password: '123', seedRPCServerAddr: ['http://seed.nkn.org:30003']));
print(wallet.address);
print(wallet.seed);
print(wallet.publicKey);

Load wallet from JSON string, note that the password needs to be the same as the one provided when creating wallet:

Wallet wallet = await Wallet.restore(w.keystore,
    config: WalletConfig(password: '123'));
print(wallet.address);
print(wallet.seed);
print(wallet.publicKey);
                      

Query asset balance for this wallet:

double balance = await wallet.getBalance();

Transfer asset to some address:

String txHash = await wallet.transfer(NKN_ADDRESS, '1.23');

Client #

NKN Client provides low level p2p messaging through NKN network.

Create a client with a generated key pair:

var client = await Client.create(WALLET_SEED);

Listen for connection established:

client.onConnect.listen((event) {
    print(event.node);
});

Receive data from other clients

client.onMessage.listen((event) {
    print(event.type);
    print(event.encrypted);
    print(event.messageId);
    print(event.data);
    print(event.src);
});

Send text message to other clients

await client.sendText([CLIENT_ADDRESS], jsonEncode({'contentType': 'text', 'content': 'Hello'}));

publish a message to a specified topic (see wallet section for subscribing to topics):

await client.publishText(TOPIC, jsonEncode({'contentType': 'text', 'content': 'Hello'}));

Pub/Sub

var res = await client.subscribe(topic: TOPIC);
var res = await client.unsubscribe(topic: TOPIC);
var res = await client.getSubscribersCount(topic: TOPIC);
var res = await client.getSubscription(topic: TOPIC, subscriber: CLIENT_ADDRESS);
7
likes
0
pub points
14%
popularity

Publisher

verified publishernkn.org

Flutter implementaion of NKN client and wallet SDK. Send and receive data for free between any NKN clients regardless their network condition without setting up a server or relying on any third party services. Data are end to end encrypted by default. Typically you might want to use multiclient instead of using client directly.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

convert, crypto, flutter, logger

More

Packages that depend on nkn_sdk_flutter