2.2.2 • Published 4 years ago

@thanos-wallet/dapp v2.2.2

Weekly downloads
352
License
MIT
Repository
github
Last release
4 years ago

ThanosWallet DApp Module

This module is required to provide communication between DApps and Thanos Wallet, it exposes unified interface for this interaction.

🚀 Quick Start

Install

yarn add @taquito/taquito @thanos-wallet/dapp

Usage

import { ThanosWallet } from "@thanos-wallet/dapp";

(async () => {
  try {
    const available = await ThanosWallet.isAvailable();
    if (!available) {
      throw new Error("Thanos Wallet not installed");
    }

    // Note:

    // use `ThanosWallet.isAvailable` method only after web application fully loaded.

    // Alternatively, you can use the method `ThanosWallet.onAvailabilityChange`
    // that tracks availability in real-time .

    const wallet = new ThanosWallet("My Super DApp");
    await wallet.connect("carthagenet");
    const tezos = wallet.toTezos();

    const accountPkh = await tezos.wallet.pkh();
    const accountBalance = await tezos.tz.getBalance(accountPkh);
    console.info(`address: ${accountPkh}, balance: ${accountBalance}`);

    const counter = await tezos.wallet.at(
      "KT1DjYkruvfujfKw6nLYafArqKufcwHuKXvT"
    );

    const operation = await counter.methods.increment(1).send();
    await operation.confirmation();

    const counterValue = await counter.storage();
    console.info(`count: ${counterValue}`);
  } catch (err) {
    console.error(err);
  }
})();

Check permissions

import { ThanosWallet } from "@thanos-wallet/dapp";

(async () => {
  try {
    const available = await ThanosWallet.isAvailable();
    if (!available) {
      throw new Error("Thanos Wallet not installed");
    }

    const permission = await ThanosWallet.getCurrentPermission();
    // Alternatively, you can use the method `ThanosWallet.onPermissionChange`
    // that tracks current permission in real-time.

    console.info(permission);
    // prints "{ rpc: string, pkh: string, publicKey: string }" if permission exists, "null" - if not.

    const wallet = new ThanosWallet("My Super DApp", permission);

    console.info(wallet.connected);
    // prints "true" if permission exists, "false" - if not.

    if (!wallet.connected) {
      await wallet.connect("carthagenet");
    }

    const tezos = wallet.toTezos();

    // ...
  } catch (err) {
    console.error(err);
  }
})();

Demo

You can find the example of Counter DApp in this repo.

API

You can explore auto generated full API Docs here.

Probably you would be most interested in the ThanosWallet class methods.

Local Development

Below is a list of commands you will probably find useful.

npm run dev or yarn dev

Runs the project in development/watch mode. Your project will be rebuilt upon changes.

Your library will be rebuilt if you make edits.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

2.2.2

4 years ago

2.2.1

4 years ago

2.2.0

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.1.3

4 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago