Last updated:
0 purchases
nkn sdk flutter
nkn-sdk-flutter #
Usage #
install #
void main() {
WidgetsFlutterBinding.ensureInitialized();
Wallet.install();
Client.install();
runApp(MyApp());
}
copied to clipboard
Wallet #
Create wallet:
Wallet wallet = await Wallet.create(null, config: WalletConfig(password: '123'));
print(wallet.address);
print(wallet.seed);
print(wallet.publicKey);
copied to clipboard
Export wallet to JSON string, where sensitive contents are encrypted by password provided in config:
wallet.keystore;
copied to clipboard
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);
copied to clipboard
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);
copied to clipboard
Query asset balance for this wallet:
double balance = await wallet.getBalance();
copied to clipboard
Transfer asset to some address:
String txHash = await wallet.transfer(NKN_ADDRESS, '1.23');
copied to clipboard
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);
copied to clipboard
Listen for connection established:
client.onConnect.listen((event) {
print(event.node);
});
copied to clipboard
Receive data from other clients
client.onMessage.listen((event) {
print(event.type);
print(event.encrypted);
print(event.messageId);
print(event.data);
print(event.src);
});
copied to clipboard
Send text message to other clients
await client.sendText([CLIENT_ADDRESS], jsonEncode({'contentType': 'text', 'content': 'Hello'}));
copied to clipboard
publish a message to a specified topic (see wallet section for subscribing to topics):
await client.publishText(TOPIC, jsonEncode({'contentType': 'text', 'content': 'Hello'}));
copied to clipboard
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);
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.