Giter VIP home page Giter VIP logo

kin.js's Introduction

kin.js

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";

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";

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";

const network = KinNetwork.Production;

Or you can create your own:

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

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.

kin.js's People

Contributors

cangoektas avatar chancity avatar dependabot[bot] avatar doc999tor avatar doodyparizada avatar liorama avatar nitzantomer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kin.js's Issues

Error in kin-sdk types

After importing the new version I face these errors

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 112
';' expected.

 L111:      PUBLIC = 'Kin Mainnet ; December 2018',
 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 112
';' expected.

 L111:      PUBLIC = 'Kin Mainnet ; December 2018',
 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 112
'=' expected.

 L111:      PUBLIC = 'Kin Mainnet ; December 2018',
 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 112
';' expected.

 L111:      PUBLIC = 'Kin Mainnet ; December 2018',
 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
';' expected.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
';' expected.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
'=' expected.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
';' expected.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
';' expected.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
';' expected.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
'=' expected.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
';' expected.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
'=' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
'=' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
';' expected.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
';' expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
Property or signature expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
Declaration or statement expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
';' expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
';' expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
Declaration or statement expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
';' expected.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
';' expected.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
Declaration or statement expected.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
';' expected.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 397
Declaration or statement expected.

 L396:  | Operation.Inflation
 L397:  | Operation.ManageData
 L398:  | Operation.BumpSequence

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 487
';' expected.

 L487:  interface Flags {
 L488:      auth_required: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
';' expected.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
'(' expected.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 489
')' expected.

 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
Duplicate identifier 'MemoType'.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 113
'string' only refers to a type, but is being used as a value here.

 L112:      TESTNET = 'Kin Testnet ; December 2018',

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
Duplicate identifier 'T'.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
Duplicate identifier 'MemoType'.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
'string' only refers to a type, but is being used as a value here.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 114
The right-hand side of an arithmetic operation must be of type 'any', 'number'or an enum type.

 L115:  export class Network {

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
Duplicate identifier 'T'.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 115
Duplicate identifier 'MemoType'.

 L115:  export class Network {
 L116:      static use(network: Network): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
Duplicate identifier 'T'.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 116
Duplicate identifier 'MemoType'.

 L115:  export class Network {
 L116:      static use(network: Network): void;
 L117:      static usePublicNetwork(): void;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
Unused label.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
'any' only refers to a type, but is being used as a value here.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 384
Cannot use namespace 'Signer' as a value.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
Cannot find name 'T'.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
Unused label.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
'any' only refers to a type, but is being used as a value here.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 385
Cannot use namespace 'Signer' as a value.

 L384:      function fromXDRObject<T extends Operation = Operation>(xdrOperation: xdr.Operation<T>): T;
 L386:  export type Operation =

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
Cannot find name 'T'.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
Unused label.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
'any' only refers to a type, but is being used as a value here.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 386
Cannot use namespace 'Signer' as a value.

 L386:  export type Operation =
 L387:      Operation.CreateAccount

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 387
'never' only refers to a type, but is being used as a value here.

 L386:  export type Operation =
 L387:      Operation.CreateAccount
 L388:      | Operation.Payment

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 389
Cannot find name 'SetOptions'.

 L388:  | Operation.Payment
 L389:  | Operation.PathPayment
 L390:  | Operation.CreatePassiveOffer

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 391
Cannot find name 'BaseOperation'.

 L390:  | Operation.CreatePassiveOffer
 L391:  | Operation.ManageOffer
 L392:  | Operation.SetOptions

[11:25:25] typescript: node_modules/@kinecosystem/kin-base/types/index.d.ts, line: 410
Namespace
'"/Users/asghaier/Documents/piggybank/kiddoKinparent/node_modules/@kinecosystem/kin-base/types/index".Operation'
has no exported member 'BumpSequence'.

 L410:      function encodePreAuthTx(data: Buffer): string;
 L411:      function decodePreAuthTx(data: string): Buffer;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 55
Type 'T' cannot be used to index type '{ [P in T]: P; } & { [P in U]: never; }& { [x: string]: never; }'.

  L54:  export namespace Config {
  L55:      function setAllowHttp(allow: boolean): void;
  L56:      function isAllowHttp(): boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 55
Type 'T' is not assignable to type 'string'. Type 'PropertyKey' is not assignable to type 'string'. Type
'number' is not assignable to type 'string'.

  L54:  export namespace Config {
  L55:      function setAllowHttp(allow: boolean): void;
  L56:      function isAllowHttp(): boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 55
Type 'U' is not assignable to type 'string'. Type 'PropertyKey' is not assignable to type 'string'. Type
'number' is not assignable to type 'string'.

  L54:  export namespace Config {
  L55:      function setAllowHttp(allow: boolean): void;
  L56:      function isAllowHttp(): boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 487
Cannot use namespace 'AssetType' as a value.

 L487:  interface Flags {
 L488:      auth_required: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 487
'BalanceLineNative' only refers to a type, but is being used as a value here.

 L487:  interface Flags {
 L488:      auth_required: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
Cannot find name 'T'.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
Cannot use namespace 'AssetType' as a value.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
Cannot use namespace 'AssetType' as a value.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
'BalanceLineAsset' only refers to a type, but is being used as a value here.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 488
Cannot find name 'T'.

 L487:  interface Flags {
 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 489
'BalanceLineNative' only refers to a type, but is being used as a value here.

 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

[11:25:25] typescript: node_modules/@kinecosystem/kin-sdk/types/index.d.ts, line: 489
'BalanceLineAsset' only refers to a type, but is being used as a value here.

 L488:      auth_required: boolean;
 L489:      auth_revocable: boolean;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.