@kinecosystem/kin.js-v1
TypeScript icon, indicating that this package has built-in type declarations

1.1.5 • Public • Published

kin.js-v1

A typescript/javascript implementation of the Kin sdk. The sdk is meant to run in both node based apps as well as in the browser.

Current state

This is still a work in progress and is not ready for use. Currently it's only possible to load an existing funded wallets.

Client

The sdk offers a client which allows to check for payments (earn and spend transactions) and to create new payments. The client interface:

interface Payment {
	readonly id: string;
	readonly hash: string;
	readonly amount: number;
	readonly sender: string;
	readonly recipient: string;
	readonly timestamp: string;
	readonly memo: string | undefined;
}

type Address = string;
type OnPaymentListener = (payment: Payment) => void;

interface KinWallet {
	getPayments(): Promise<Payment[]>;
	onPaymentReceived(listener: OnPaymentListener): void;
	pay(recipient: Address, amount: number, memo?: string): Promise<Payment>;
}

In order to create a wallet:

import { KinWallet, createWallet, KinNetwork, Keypair } from "@kinecosystem/kin.js-v1";

async function createKinWallet(): Promise<KinWallet> {
	const keys = Keypair.random();
	const network = KinNetwork.Testnet;
	
	return await createWallet(network, keys);
}

Or using promises (without async/await):

import { KinWallet, createWallet, KinNetwork, Keypair } from "@kinecosystem/kin.js-v1";

const keys = Keypair.random();
const network = KinNetwork.Testnet;
	
let wallet: KinWallet | undefined;
createWallet(network, keys).then(w => wallet = w);

For production use the appropriate network:

import { KinNetwork } from "@kinecosystem/kin.js-v1";

const network = KinNetwork.Production;

Or you can create your own:

import { KinNetwork } from "@kinecosystem/kin.js-v1";

const network = KinNetwork.from(
	"network passphrase",
	"asset issuer",
	"horizon url");

To get the Kin balance from a wallet:

const wallet = getWallet(); // get the wallet somehow
let balance = wallet.balance.cached();

Or to get the current balance:

let balance = await wallet.balance.update();

The update() method will also update the cached value.

Readme

Keywords

none

Package Sidebar

Install

npm i @kinecosystem/kin.js-v1

Weekly Downloads

1

Version

1.1.5

License

MIT

Unpacked Size

60 kB

Total Files

27

Last publish

Collaborators

  • kin-foundation
  • kikengineering