GithubHelp home page GithubHelp logo

dsawali / templewallet-dapp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from madfish-solutions/templewallet-dapp

0.0 0.0 0.0 434 KB

๐Ÿ‘พ This module is required to provide communication between DApps and Temple Wallet

Home Page: https://templewallet.com

License: MIT License

TypeScript 100.00%

templewallet-dapp's Introduction

TempleWallet DApp Module

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

๐Ÿš€ Quick Start

Install

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

Usage

import { TempleWallet } from "@temple-wallet/dapp";

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

    // Note:

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

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

    const wallet = new TempleWallet("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 { TempleWallet } from "@temple-wallet/dapp";

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

    const permission = await TempleWallet.getCurrentPermission();
    // Alternatively, you can use the method `TempleWallet.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 TempleWallet("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);
  }
})();

Sign

import { TempleWallet } from "@temple-wallet/dapp";

(async () => {
  try {
    const wallet = new TempleWallet("My Super DApp");
    // ...

    // Only hex strings
    const signature = await wallet.sign(
      Buffer.from("Hello world").toString("hex")
    );
  } 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 TempleWallet 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).

templewallet-dapp's People

Contributors

serg-plusplus avatar lourenc avatar dsawali avatar romarq avatar

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.